Compare commits
No commits in common. "master" and "v1.0" have entirely different histories.
BIN
bin/assets/images/Unbenannt.png
Normal file
BIN
bin/assets/images/Unbenannt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 93 KiB |
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
42
gameover.c
42
gameover.c
@ -13,14 +13,12 @@
|
||||
#include "vector.h"
|
||||
#include "highscores.h"
|
||||
#include "background.h"
|
||||
#include "startmenu.h"
|
||||
#include "main.h"
|
||||
|
||||
#define GAMEOVER_TexturePath "assets/images/gameover.png"
|
||||
#define GAMEOVER_NumbersTexturePath "assets/images/numbers.png"
|
||||
#define GAMEOVER_ScoreTexturePath "assets/images/yourscore.png"
|
||||
#define GAMEOVER_UploadTexturePath "assets/images/upload.png"
|
||||
#define GAMEOVER_RestartTexturePath "assets/images/restart_button.png"
|
||||
#define GAMEOVER_HUDScale 16.0f
|
||||
#define GAMEOVER_Scale 4.0f
|
||||
|
||||
@ -30,24 +28,17 @@ extern bool LoggedIn;
|
||||
|
||||
extern int width, height;
|
||||
|
||||
extern SDL_Texture * HIGHSCORESBUTTON_Texture;
|
||||
extern SDL_Texture * QUITBUTTON_Texture;
|
||||
extern SDL_Rect QUITBUTTON_Rect;
|
||||
|
||||
int GAMEOVER_HUDMargin = 5;
|
||||
SDL_Texture * GAMEOVER_Texture;
|
||||
SDL_Texture * GAMEOVER_Numbers;
|
||||
SDL_Texture * GAMEOVER_ScoreTexture;
|
||||
SDL_Texture * GAMEOVER_UploadTexture;
|
||||
SDL_Texture * GAMEOVER_RestartTexture;
|
||||
SDL_Rect * GAMEOVER_NumberRects;
|
||||
SDL_Rect * GAMEOVER_UploadRects;
|
||||
SDL_Rect GAMEOVER_TargetRect;
|
||||
SDL_Rect GAMEOVER_ScoreTargetRect;
|
||||
SDL_Rect GAMEOVER_HUDScoreTargetRect;
|
||||
SDL_Rect * GAMEOVER_UploadTargetRects;
|
||||
SDL_Rect GAMEOVER_HighscoresButtonRect;
|
||||
SDL_Rect GAMEOVER_RestartButtonRect;
|
||||
int * GAMEOVER_Digits;
|
||||
bool GAMEOVER_IsInit = false;
|
||||
UploadState GAMEOVER_UploadState = Initial;
|
||||
@ -64,8 +55,6 @@ void GAMEOVER_Initialize(SDL_Renderer * renderer){
|
||||
if (!GAMEOVER_ScoreTexture) printf("Gameover Score Texture couldn't be loaded!\n");
|
||||
GAMEOVER_UploadTexture = IMG_LoadTexture(renderer, GAMEOVER_UploadTexturePath);
|
||||
if (!GAMEOVER_UploadTexture) printf("Gameover Score Texture couldn't be loaded!\n");
|
||||
GAMEOVER_RestartTexture = IMG_LoadTexture(renderer, GAMEOVER_RestartTexturePath);
|
||||
if (!GAMEOVER_RestartTexture) printf("Restart Button Texture couldn't be loaded!\n");
|
||||
int w, h;
|
||||
SDL_QueryTexture(GAMEOVER_Texture, NULL, NULL, &w, &h);
|
||||
w /= 2;
|
||||
@ -100,12 +89,9 @@ void GAMEOVER_Initialize(SDL_Renderer * renderer){
|
||||
if (!GAMEOVER_UploadTargetRects) printf("FATAL: Memory Allocation Failed!\n");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
GAMEOVER_UploadTargetRects[i] = (SDL_Rect) {.x = 0, .y = 650, .w = ((GAMEOVER_UploadRects[i].w) / 5), .h = ((GAMEOVER_UploadRects[i].h) / 5) };
|
||||
GAMEOVER_UploadTargetRects[i].x = ((width - (GAMEOVER_UploadTargetRects[i].w)) / 2);
|
||||
}
|
||||
GAMEOVER_HUDScoreTargetRect = (SDL_Rect) {.x = GAMEOVER_HUDMargin, .y = GAMEOVER_HUDMargin, .w = 250, .h = 46 };
|
||||
GAMEOVER_Digits = malloc(25 * sizeof(int)); // Holds every digit of unsigned long long int
|
||||
GAMEOVER_HighscoresButtonRect = (SDL_Rect) {.x = 1635, .y = 896, .w = 235, .h = 134 };
|
||||
GAMEOVER_RestartButtonRect = (SDL_Rect) {.x = 842, .y = 896, .w = 235, .h = 134 };
|
||||
GAMEOVER_Digits = malloc(25 * sizeof(int));
|
||||
printf("Gameover initialized!\n");
|
||||
GAMEOVER_IsInit = true;
|
||||
} else
|
||||
@ -114,11 +100,10 @@ void GAMEOVER_Initialize(SDL_Renderer * renderer){
|
||||
|
||||
void GAMEOVER_MouseClicked(SDL_MouseButtonEvent b, Scenery * scenery){
|
||||
if (b.button == SDL_BUTTON_LEFT) {
|
||||
if (LoggedIn) {
|
||||
if (LoggedIn)
|
||||
if (GAMEOVER_UploadState == Initial || GAMEOVER_UploadState == Failed) {
|
||||
if (clickInRect(b, (GAMEOVER_UploadTargetRects + GAMEOVER_UploadState))) {
|
||||
GAMEOVER_UploadState = Uploading;
|
||||
printf("Upload was called from gameover!\n");
|
||||
if (HIGHSCORES_UploadScore(Username, (scenery->Score))) {
|
||||
GAMEOVER_UploadState = Finished;
|
||||
} else {
|
||||
@ -127,19 +112,7 @@ void GAMEOVER_MouseClicked(SDL_MouseButtonEvent b, Scenery * scenery){
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clickInRect(b, &QUITBUTTON_Rect)) {
|
||||
printf("Escape was called from gameover!\n");
|
||||
GAME_Escape();
|
||||
} else if (clickInRect(b, &GAMEOVER_HighscoresButtonRect)) {
|
||||
printf("Highscores was called from gameover!\n");
|
||||
GAME_ChangeState(Highscores);
|
||||
} else if (clickInRect(b, &GAMEOVER_RestartButtonRect)) {
|
||||
printf("Restart was called from gameover!\n");
|
||||
GAME_Restart();
|
||||
GAME_ChangeState(Game);
|
||||
}
|
||||
}
|
||||
} /* GAMEOVER_MouseClicked */
|
||||
}
|
||||
|
||||
void GAMEOVER_Draw(SDL_Renderer * renderer, Scenery * scenery){
|
||||
int i, count;
|
||||
@ -162,12 +135,8 @@ void GAMEOVER_Draw(SDL_Renderer * renderer, Scenery * scenery){
|
||||
SDL_RenderCopy(renderer, GAMEOVER_Numbers, (GAMEOVER_NumberRects + GAMEOVER_Digits[i]), &target);
|
||||
xOffset += target.w - 1;
|
||||
}
|
||||
if (LoggedIn) {
|
||||
SDL_RenderCopy(renderer, GAMEOVER_UploadTexture, (GAMEOVER_UploadRects + GAMEOVER_UploadState), (GAMEOVER_UploadTargetRects + GAMEOVER_UploadState));
|
||||
}
|
||||
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
||||
SDL_RenderCopy(renderer, HIGHSCORESBUTTON_Texture, NULL, &GAMEOVER_HighscoresButtonRect);
|
||||
SDL_RenderCopy(renderer, GAMEOVER_RestartTexture, NULL, &GAMEOVER_RestartButtonRect);
|
||||
if (LoggedIn)
|
||||
GAMEOVER_DrawHorizontalCenter(renderer, GAMEOVER_UploadTexture, (GAMEOVER_UploadRects + GAMEOVER_UploadState), (GAMEOVER_UploadTargetRects + GAMEOVER_UploadState));
|
||||
} /* GAMEOVER_Draw */
|
||||
|
||||
void GAMEOVER_DrawHorizontalCenter(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Rect * srcRect, SDL_Rect * dstRect){
|
||||
@ -221,7 +190,6 @@ void GAMEOVER_Deinitialize(){
|
||||
free(GAMEOVER_NumberRects);
|
||||
free(GAMEOVER_UploadRects);
|
||||
free(GAMEOVER_UploadTargetRects);
|
||||
SDL_DestroyTexture(GAMEOVER_RestartTexture);
|
||||
SDL_DestroyTexture(GAMEOVER_Texture);
|
||||
SDL_DestroyTexture(GAMEOVER_ScoreTexture);
|
||||
SDL_DestroyTexture(GAMEOVER_Numbers);
|
||||
|
20
highscores.c
20
highscores.c
@ -7,13 +7,10 @@
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
#include "highscores.h"
|
||||
#include "main.h"
|
||||
|
||||
#define HIGHSCORES_FontFile "assets/fonts/monofur.ttf"
|
||||
#define HIGHSCORES_OutputFilePath "output.txt"
|
||||
|
||||
extern SDL_Texture * Return_Button_Texture;
|
||||
|
||||
int HIGHSCORES_EntriesGot = 0;
|
||||
User * HIGHSCORES_UserList;
|
||||
SDL_Color HIGHSCORES_FontColor;
|
||||
@ -21,7 +18,6 @@ SDL_Texture * HIGHSCORES_TableTexture;
|
||||
SDL_Rect HIGHSCORES_TotalRect;
|
||||
TTF_Font * HIGHSCORES_FontFamily = NULL;
|
||||
SDL_Surface * tempSurface;
|
||||
SDL_Rect HIGHSCORES_ReturnButtonRect;
|
||||
|
||||
void HIGHSCORES_Initialize(){
|
||||
printf("Initializing Highscores...\n");
|
||||
@ -29,12 +25,9 @@ void HIGHSCORES_Initialize(){
|
||||
HIGHSCORES_UserList = malloc(10 * sizeof(User));
|
||||
HIGHSCORES_FontFamily = TTF_OpenFont(HIGHSCORES_FontFile, 48);
|
||||
if (!HIGHSCORES_FontFamily) printf("Font could not initialize! Error: %s\n", TTF_GetError());
|
||||
else {
|
||||
printf("Font was successfully initialized!\n");
|
||||
else printf("Font was successfully initialized!\n");
|
||||
printFontStyle(HIGHSCORES_FontFamily);
|
||||
}
|
||||
HIGHSCORES_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 };
|
||||
HIGHSCORES_ReturnButtonRect = (SDL_Rect) {.x = 10, .y = 970, .w = 100, .h = 100 };
|
||||
printf("Highscores initialized!\n");
|
||||
}
|
||||
|
||||
@ -58,17 +51,8 @@ void printFontStyle(TTF_Font * ffont){
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void HIGHSCORES_MouseClicked(SDL_MouseButtonEvent b){
|
||||
if (b.button == SDL_BUTTON_LEFT) {
|
||||
if (clickInRect(b, &HIGHSCORES_ReturnButtonRect)) {
|
||||
GAME_ReturnToLastScreen();
|
||||
}
|
||||
}
|
||||
} /* GAMEOVER_MouseClicked */
|
||||
|
||||
void HIGHSCORES_Draw(SDL_Renderer * renderer){
|
||||
SDL_RenderCopy(renderer, HIGHSCORES_TableTexture, &HIGHSCORES_TotalRect, &HIGHSCORES_TotalRect);
|
||||
SDL_RenderCopy(renderer, Return_Button_Texture, NULL, &HIGHSCORES_ReturnButtonRect);
|
||||
} /* HIGHSCORES_Draw */
|
||||
|
||||
void HIGHSCORES_Deinitialize(){
|
||||
@ -126,7 +110,7 @@ bool HIGHSCORES_UploadScore(char * username, int score){
|
||||
ssize_t read;
|
||||
|
||||
sprintf(buffer, "bhi upload %s %s %d", HIGHSCORES_OutputFilePath, username, score);
|
||||
// printf("BHI called with \"%s\"\n", buffer);
|
||||
printf("BHI called with \"%s\"\n", buffer);
|
||||
// printf("Call BHI interface:\n");
|
||||
system(buffer);
|
||||
// printf("BHI interface quit!\nBHI output handling...\n");
|
||||
|
@ -10,7 +10,6 @@ typedef struct userStruct {
|
||||
// Prototypes
|
||||
void HIGHSCORES_Initialize();
|
||||
void printFontStyle(TTF_Font * ffont);
|
||||
void HIGHSCORES_MouseClicked(SDL_MouseButtonEvent b);
|
||||
void HIGHSCORES_Draw(SDL_Renderer * renderer);
|
||||
void HIGHSCORES_Deinitialize();
|
||||
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer);
|
||||
|
25
main.c
25
main.c
@ -37,7 +37,6 @@ SDL_Renderer * renderer;
|
||||
SDL_Event event;
|
||||
bool running = true, fullscreen = false, LoggedIn = false;
|
||||
GameState gameState = MainMenu;
|
||||
GameState previousGameState = MainMenu;
|
||||
Scenery scenery;
|
||||
Mix_Music * MenuLoop;
|
||||
char * Username;
|
||||
@ -248,7 +247,6 @@ void GAME_ChangeState(GameState state){
|
||||
printf("State wasn't changed!\n");
|
||||
return;
|
||||
}
|
||||
previousGameState = gameState;
|
||||
gameState = state;
|
||||
switch (gameState) {
|
||||
case Game:
|
||||
@ -264,13 +262,6 @@ void GAME_ChangeState(GameState state){
|
||||
break;
|
||||
}
|
||||
} /* GAME_ChangeState */
|
||||
void GAME_ReturnToLastScreen(){
|
||||
if (previousGameState == gameState) {
|
||||
printf("Cannot \"return\" to the same screen!\n");
|
||||
} else {
|
||||
GAME_ChangeState(previousGameState);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleSDLEvents(){
|
||||
while (SDL_PollEvent(&event)) {
|
||||
@ -286,6 +277,7 @@ void HandleSDLEvents(){
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mousePress(event.button);
|
||||
button_clicked(event.button, gameState);
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
windowChanged(event.window);
|
||||
@ -299,12 +291,6 @@ void mousePress(SDL_MouseButtonEvent b){ // Debug prop
|
||||
case GameOver:
|
||||
GAMEOVER_MouseClicked(b, &scenery);
|
||||
break;
|
||||
case MainMenu:
|
||||
STARTMENU_ButtonClicked(event.button, gameState);
|
||||
break;
|
||||
case Highscores:
|
||||
HIGHSCORES_MouseClicked(b);
|
||||
break;
|
||||
default:
|
||||
printf("Gamestate currently ignores Mouse press event: %d!\n", gameState);
|
||||
break;
|
||||
@ -316,7 +302,7 @@ void mousePress(SDL_MouseButtonEvent b){ // Debug prop
|
||||
} else {
|
||||
printf("Unknown mouse button pressed: %d\n", b.button);
|
||||
}
|
||||
} /* mousePress */
|
||||
}
|
||||
|
||||
void keyPress(SDL_KeyboardEvent b){ // Debug prop
|
||||
printf("Key pressed: ID is %d\n", b.keysym.scancode);
|
||||
@ -359,11 +345,6 @@ void DrawBackground(SDL_Renderer * renderer){
|
||||
SDL_RenderClear(renderer);
|
||||
} /* DrawFrame */
|
||||
|
||||
void GAME_Restart(){
|
||||
printf("Starting new game!\n");
|
||||
scenery = BREAKOUT_CreateDefault();
|
||||
}
|
||||
|
||||
void INITIALIZE(){
|
||||
printf("Initializing started...\n");
|
||||
srand(time(NULL));
|
||||
@ -384,7 +365,7 @@ void INITIALIZE(){
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
printf("Renderer was created!\n");
|
||||
BREAKOUT_INITIALIZE(renderer);
|
||||
GAME_Restart();
|
||||
scenery = BREAKOUT_CreateDefault();
|
||||
Load_Textures(renderer);
|
||||
HIGHSCORES_Initialize();
|
||||
BACKGROUND_Initialize(renderer, width, height);
|
||||
|
2
main.h
2
main.h
@ -40,14 +40,12 @@ void GAME_Escape();
|
||||
void MENU_StartMusic();
|
||||
void MENU_PauseMusic();
|
||||
void GAME_ChangeState(GameState state);
|
||||
void GAME_ReturnToLastScreen();
|
||||
void HandleSDLEvents();
|
||||
void mousePress(SDL_MouseButtonEvent b);
|
||||
void keyPress(SDL_KeyboardEvent b);
|
||||
void toggleFullscreen();
|
||||
void windowChanged(SDL_WindowEvent b);
|
||||
void DrawBackground(SDL_Renderer * renderer);
|
||||
void GAME_Restart();
|
||||
void INITIALIZE();
|
||||
void QUIT();
|
||||
// End Prototypes
|
||||
|
@ -53,7 +53,8 @@ void Startmenu_Draw(SDL_Renderer * renderer) {
|
||||
SDL_RenderCopy(renderer, QUITBUTTON_Texture, NULL, &QUITBUTTON_Rect);
|
||||
}
|
||||
|
||||
void STARTMENU_ButtonClicked(SDL_MouseButtonEvent b, GameState gameState) {
|
||||
void button_clicked(SDL_MouseButtonEvent b, GameState gameState) {
|
||||
if (gameState == MainMenu) {
|
||||
if (clickInRect(b, &PLAYBUTTON_Rect) == 1) {
|
||||
GAME_ChangeState(Game);
|
||||
} else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) {
|
||||
@ -63,4 +64,5 @@ void STARTMENU_ButtonClicked(SDL_MouseButtonEvent b, GameState gameState) {
|
||||
} else if (clickInRect(b, &QUITBUTTON_Rect) == 1) {
|
||||
GAME_Escape();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ void Load_Textures (SDL_Renderer* renderer);
|
||||
|
||||
void Startmenu_Draw (SDL_Renderer* renderer);
|
||||
|
||||
void STARTMENU_ButtonClicked(SDL_MouseButtonEvent b, GameState gameState);
|
||||
void button_clicked(SDL_MouseButtonEvent b, GameState gameState);
|
||||
|
||||
int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user