From 38a81c319a88db82a8248b98798d275c790b4f32 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Thu, 18 Jan 2018 15:45:33 +0100 Subject: [PATCH] Variables renamed for convenience --- highscores.c | 48 +++++++++++++++++++-------------------- startmenu.c | 63 ++++++++++++++++++++++++++-------------------------- 2 files changed, 56 insertions(+), 55 deletions(-) diff --git a/highscores.c b/highscores.c index 5a06164..f9f019e 100644 --- a/highscores.c +++ b/highscores.c @@ -8,23 +8,23 @@ #include "highscores.h" -#define HIGHSCORES_FontFamily "assets/fonts/monofur.ttf" +#define HIGHSCORES_FontFile "assets/fonts/monofur.ttf" -int entriesGot = 0; -User * ul; -SDL_Color White; +int HIGHSCORES_EntriesGot = 0; +User * HIGHSCORES_UserList; +SDL_Color HIGHSCORES_FontColor; SDL_Texture * HIGHSCORES_TableTexture; SDL_Rect HIGHSCORES_TotalRect; -TTF_Font * font = NULL; +TTF_Font * HIGHSCORES_FontFamily = NULL; void HIGHSCORES_Initialize(){ printf("Initializing Highscores...\n"); - White = (SDL_Color) {255, 255, 255 }; - ul = malloc(10 * sizeof(User)); - font = TTF_OpenFont(HIGHSCORES_FontFamily, 48); - if (!font) printf("Font could not initialize! Error: %s\n", TTF_GetError()); - else printf("Font was successfully initialized!\n"); - printFontStyle(font); + HIGHSCORES_FontColor = (SDL_Color) {255, 255, 255 }; + HIGHSCORES_UserList = malloc(10 * sizeof(User)); + HIGHSCORES_FontFamily = TTF_OpenFont(HIGHSCORES_FontFile, 48); + if (!HIGHSCORES_FontFamily) printf("Font coHIGHSCORES_UserListd not initialize! Error: %s\n", TTF_GetError()); + else printf("Font was successfHIGHSCORES_UserListly initialized!\n"); + printFontStyle(HIGHSCORES_FontFamily); HIGHSCORES_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 }; printf("Highscores initialized!\n"); } @@ -55,10 +55,10 @@ void HIGHSCORES_Draw(SDL_Renderer * renderer){ void HIGHSCORES_Deinitialize(){ printf("De-initializing Highscores...\n"); - TTF_CloseFont(font); - font = NULL; // to be safe... + TTF_CloseFont(HIGHSCORES_FontFamily); + HIGHSCORES_FontFamily = NULL; // to be safe... SDL_DestroyTexture(HIGHSCORES_TableTexture); - free(ul); + free(HIGHSCORES_UserList); printf("Highscores de-initialized!\n"); } @@ -75,8 +75,8 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){ Message_rect.x = 50; SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect); SDL_FreeSurface(tempSurface); - while (count < entriesGot) { - sprintf(buffer, format, ul[count].Username, ul[count].Score); + while (count < HIGHSCORES_EntriesGot) { + sprintf(buffer, format, HIGHSCORES_UserList[count].Username, HIGHSCORES_UserList[count].Score); tempSurface = HIGHSCORES_DrawText(buffer, &Message_rect); Message_rect.y = ((Message_rect.h + 15) * (count + 1)) + 140; Message_rect.x = 50; @@ -89,8 +89,8 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){ } /* HIGHSCORES_GenerateSurface */ SDL_Surface * HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){ - TTF_SizeText(font, text, &(Message_rect->w), &(Message_rect->h)); - SDL_Surface * tempSurface = TTF_RenderText_Solid(font, text, White); + TTF_SizeText(HIGHSCORES_FontFamily, text, &(Message_rect->w), &(Message_rect->h)); + SDL_Surface * tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor); return tempSurface; } @@ -99,7 +99,7 @@ void HIGHSCORES_ReloadList(){ system("bhi top output.txt"); printf("BHI interface quit!\nBHI output handling...\n"); - entriesGot = 0; + HIGHSCORES_EntriesGot = 0; FILE * fp; char * line = NULL; size_t len = 0; @@ -107,7 +107,7 @@ void HIGHSCORES_ReloadList(){ char * name, * scorestring; int nameCharCount = 0, scoreCharCount = 0; bool switchread = false; - ul = malloc(10 * sizeof(User)); + HIGHSCORES_UserList = malloc(10 * sizeof(User)); fp = fopen("output.txt", "r"); if (fp == NULL) return; @@ -141,7 +141,7 @@ void HIGHSCORES_ReloadList(){ User tmp; strcpy(tmp.Username, name); strcpy(tmp.Score, scorestring); - ul[counter++] = tmp; + HIGHSCORES_UserList[counter++] = tmp; } free(name); free(scorestring); @@ -150,9 +150,9 @@ void HIGHSCORES_ReloadList(){ if (line) free(line); for (size_t i = 0; i < counter; i++) { - printf("User: %s -> Score: %s\n", ul[i].Username, ul[i].Score); + printf("User: %s -> Score: %s\n", HIGHSCORES_UserList[i].Username, HIGHSCORES_UserList[i].Score); } - entriesGot = counter; - printf("BHI Interface successfully quit!\n"); + HIGHSCORES_EntriesGot = counter; + printf("BHI Interface successfHIGHSCORES_UserListly quit!\n"); } /* main */ diff --git a/startmenu.c b/startmenu.c index 7eb677e..3acf979 100644 --- a/startmenu.c +++ b/startmenu.c @@ -3,15 +3,16 @@ #include #include #include "gamestate.h" +#include "main.h" -SDL_Texture* TITLE_Texture; -SDL_Texture* PLAYBUTTON_Texture; -SDL_Texture* SKINSBUTTON_Texture; -SDL_Texture* LEVELBUTTON_Texture; -SDL_Texture* SETTINGSBUTTON_Texture; -SDL_Texture* HIGHSCORESBUTTON_Texture; -SDL_Texture* QUITBUTTON_Texture; +SDL_Texture * TITLE_Texture; +SDL_Texture * PLAYBUTTON_Texture; +SDL_Texture * SKINSBUTTON_Texture; +SDL_Texture * LEVELBUTTON_Texture; +SDL_Texture * SETTINGSBUTTON_Texture; +SDL_Texture * HIGHSCORESBUTTON_Texture; +SDL_Texture * QUITBUTTON_Texture; SDL_Rect TITLE_Rect; SDL_Rect PLAYBUTTON_Rect; @@ -21,34 +22,34 @@ SDL_Rect SKINSBUTTON_Rect; SDL_Rect HIGHSCORESBUTTON_Rect; SDL_Rect QUITBUTTON_Rect; -int clickInRect(SDL_MouseButtonEvent b, SDL_Rect* area_rect) { +int clickInRect(SDL_MouseButtonEvent b, SDL_Rect * area_rect) { return (((b.x) >= (area_rect->x)) && ((b.x) <= ((area_rect->x) + (area_rect->w))) && ((b.y) >= (area_rect->y)) && ((b.y) <= ((area_rect->y) + (area_rect->h)))); } -void Load_Textures (SDL_Renderer* renderer) { +void Load_Textures(SDL_Renderer * renderer) { TITLE_Texture = IMG_LoadTexture(renderer, "assets/images/breaking_button.png"); - TITLE_Rect = (SDL_Rect){.x = 685,.y = 50, .w=550, .h=250}; + TITLE_Rect = (SDL_Rect) {.x = 685, .y = 50, .w = 550, .h = 250 }; PLAYBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/play_button.png"); - PLAYBUTTON_Rect = (SDL_Rect){.x = 497, .y = 400, .w=313, .h=178}; + PLAYBUTTON_Rect = (SDL_Rect) {.x = 497, .y = 400, .w = 313, .h = 178 }; SKINSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/skins_button.png"); - SKINSBUTTON_Rect = (SDL_Rect){.x = 1110, .y = 400, .w=313, .h=178}; + SKINSBUTTON_Rect = (SDL_Rect) {.x = 1110, .y = 400, .w = 313, .h = 178 }; LEVELBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/level_button.png"); - LEVELBUTTON_Rect = (SDL_Rect){.x = 497, .y = 700, .w=313, .h=178}; + LEVELBUTTON_Rect = (SDL_Rect) {.x = 497, .y = 700, .w = 313, .h = 178 }; SETTINGSBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/settings_button.png"); - SETTINGSBUTTON_Rect = (SDL_Rect){.x = 1110, .y = 700, .w=313, .h=178}; + SETTINGSBUTTON_Rect = (SDL_Rect) {.x = 1110, .y = 700, .w = 313, .h = 178 }; HIGHSCORESBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/highscores_button.png"); - HIGHSCORESBUTTON_Rect = (SDL_Rect){.x = 1557, .y = 120, .w=313, .h=178}; + HIGHSCORESBUTTON_Rect = (SDL_Rect) {.x = 1557, .y = 120, .w = 313, .h = 178 }; QUITBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/quit_button.png"); - QUITBUTTON_Rect = (SDL_Rect){.x = 50, .y = 896 , .w=235, .h=134}; -} + QUITBUTTON_Rect = (SDL_Rect) {.x = 50, .y = 896, .w = 235, .h = 134 }; +} /* Load_Textures */ -void Startmenu_Draw (SDL_Renderer* renderer) { +void Startmenu_Draw(SDL_Renderer * renderer) { SDL_RenderCopy(renderer, TITLE_Texture, NULL, &TITLE_Rect); SDL_RenderCopy(renderer, PLAYBUTTON_Texture, NULL, &PLAYBUTTON_Rect); SDL_RenderCopy(renderer, SKINSBUTTON_Texture, NULL, &SKINSBUTTON_Rect); @@ -59,17 +60,17 @@ void Startmenu_Draw (SDL_Renderer* renderer) { } void button_clicked(SDL_MouseButtonEvent b) { - if(clickInRect(b, &PLAYBUTTON_Rect) == 1) { - GAME_ChangeState(Game); - } else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) { - GAME_ChangeState(SkinSelect); - } else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) { - GAME_ChangeState(LevelSelect); - } else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) { - GAME_ChangeState(Settings); - } else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) { - GAME_ChangeState(Highscores); - } else if (clickInRect(b, &QUITBUTTON_Rect) == 1) { - GAME_Escape(); - } + if (clickInRect(b, &PLAYBUTTON_Rect) == 1) { + GAME_ChangeState(Game); + } else if (clickInRect(b, &SKINSBUTTON_Rect) == 1) { + GAME_ChangeState(SkinSelect); + } else if (clickInRect(b, &LEVELBUTTON_Rect) == 1) { + GAME_ChangeState(LevelSelect); + } else if (clickInRect(b, &SETTINGSBUTTON_Rect) == 1) { + GAME_ChangeState(Settings); + } else if (clickInRect(b, &HIGHSCORESBUTTON_Rect) == 1) { + GAME_ChangeState(Highscores); + } else if (clickInRect(b, &QUITBUTTON_Rect) == 1) { + GAME_Escape(); + } }