Variables renamed for convenience

This commit is contained in:
Michael Chen 2018-01-18 15:45:33 +01:00
parent 24e6e2c76f
commit 38a81c319a
2 changed files with 56 additions and 55 deletions

View File

@ -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 */

View File

@ -3,6 +3,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "gamestate.h"
#include "main.h"
SDL_Texture * TITLE_Texture;
@ -46,7 +47,7 @@ void Load_Textures (SDL_Renderer* renderer) {
QUITBUTTON_Texture = IMG_LoadTexture(renderer, "assets/images/quit_button.png");
QUITBUTTON_Rect = (SDL_Rect) {.x = 50, .y = 896, .w = 235, .h = 134 };
}
} /* Load_Textures */
void Startmenu_Draw(SDL_Renderer * renderer) {
SDL_RenderCopy(renderer, TITLE_Texture, NULL, &TITLE_Rect);