Variables renamed for convenience
This commit is contained in:
parent
24e6e2c76f
commit
38a81c319a
48
highscores.c
48
highscores.c
@ -8,23 +8,23 @@
|
|||||||
|
|
||||||
#include "highscores.h"
|
#include "highscores.h"
|
||||||
|
|
||||||
#define HIGHSCORES_FontFamily "assets/fonts/monofur.ttf"
|
#define HIGHSCORES_FontFile "assets/fonts/monofur.ttf"
|
||||||
|
|
||||||
int entriesGot = 0;
|
int HIGHSCORES_EntriesGot = 0;
|
||||||
User * ul;
|
User * HIGHSCORES_UserList;
|
||||||
SDL_Color White;
|
SDL_Color HIGHSCORES_FontColor;
|
||||||
SDL_Texture * HIGHSCORES_TableTexture;
|
SDL_Texture * HIGHSCORES_TableTexture;
|
||||||
SDL_Rect HIGHSCORES_TotalRect;
|
SDL_Rect HIGHSCORES_TotalRect;
|
||||||
TTF_Font * font = NULL;
|
TTF_Font * HIGHSCORES_FontFamily = NULL;
|
||||||
|
|
||||||
void HIGHSCORES_Initialize(){
|
void HIGHSCORES_Initialize(){
|
||||||
printf("Initializing Highscores...\n");
|
printf("Initializing Highscores...\n");
|
||||||
White = (SDL_Color) {255, 255, 255 };
|
HIGHSCORES_FontColor = (SDL_Color) {255, 255, 255 };
|
||||||
ul = malloc(10 * sizeof(User));
|
HIGHSCORES_UserList = malloc(10 * sizeof(User));
|
||||||
font = TTF_OpenFont(HIGHSCORES_FontFamily, 48);
|
HIGHSCORES_FontFamily = TTF_OpenFont(HIGHSCORES_FontFile, 48);
|
||||||
if (!font) printf("Font could not initialize! Error: %s\n", TTF_GetError());
|
if (!HIGHSCORES_FontFamily) printf("Font coHIGHSCORES_UserListd not initialize! Error: %s\n", TTF_GetError());
|
||||||
else printf("Font was successfully initialized!\n");
|
else printf("Font was successfHIGHSCORES_UserListly initialized!\n");
|
||||||
printFontStyle(font);
|
printFontStyle(HIGHSCORES_FontFamily);
|
||||||
HIGHSCORES_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 };
|
HIGHSCORES_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 };
|
||||||
printf("Highscores initialized!\n");
|
printf("Highscores initialized!\n");
|
||||||
}
|
}
|
||||||
@ -55,10 +55,10 @@ void HIGHSCORES_Draw(SDL_Renderer * renderer){
|
|||||||
|
|
||||||
void HIGHSCORES_Deinitialize(){
|
void HIGHSCORES_Deinitialize(){
|
||||||
printf("De-initializing Highscores...\n");
|
printf("De-initializing Highscores...\n");
|
||||||
TTF_CloseFont(font);
|
TTF_CloseFont(HIGHSCORES_FontFamily);
|
||||||
font = NULL; // to be safe...
|
HIGHSCORES_FontFamily = NULL; // to be safe...
|
||||||
SDL_DestroyTexture(HIGHSCORES_TableTexture);
|
SDL_DestroyTexture(HIGHSCORES_TableTexture);
|
||||||
free(ul);
|
free(HIGHSCORES_UserList);
|
||||||
printf("Highscores de-initialized!\n");
|
printf("Highscores de-initialized!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +75,8 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
|
|||||||
Message_rect.x = 50;
|
Message_rect.x = 50;
|
||||||
SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect);
|
SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect);
|
||||||
SDL_FreeSurface(tempSurface);
|
SDL_FreeSurface(tempSurface);
|
||||||
while (count < entriesGot) {
|
while (count < HIGHSCORES_EntriesGot) {
|
||||||
sprintf(buffer, format, ul[count].Username, ul[count].Score);
|
sprintf(buffer, format, HIGHSCORES_UserList[count].Username, HIGHSCORES_UserList[count].Score);
|
||||||
tempSurface = HIGHSCORES_DrawText(buffer, &Message_rect);
|
tempSurface = HIGHSCORES_DrawText(buffer, &Message_rect);
|
||||||
Message_rect.y = ((Message_rect.h + 15) * (count + 1)) + 140;
|
Message_rect.y = ((Message_rect.h + 15) * (count + 1)) + 140;
|
||||||
Message_rect.x = 50;
|
Message_rect.x = 50;
|
||||||
@ -89,8 +89,8 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
|
|||||||
} /* HIGHSCORES_GenerateSurface */
|
} /* HIGHSCORES_GenerateSurface */
|
||||||
|
|
||||||
SDL_Surface * HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){
|
SDL_Surface * HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){
|
||||||
TTF_SizeText(font, text, &(Message_rect->w), &(Message_rect->h));
|
TTF_SizeText(HIGHSCORES_FontFamily, text, &(Message_rect->w), &(Message_rect->h));
|
||||||
SDL_Surface * tempSurface = TTF_RenderText_Solid(font, text, White);
|
SDL_Surface * tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
|
||||||
return tempSurface;
|
return tempSurface;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ void HIGHSCORES_ReloadList(){
|
|||||||
system("bhi top output.txt");
|
system("bhi top output.txt");
|
||||||
printf("BHI interface quit!\nBHI output handling...\n");
|
printf("BHI interface quit!\nBHI output handling...\n");
|
||||||
|
|
||||||
entriesGot = 0;
|
HIGHSCORES_EntriesGot = 0;
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
char * line = NULL;
|
char * line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
@ -107,7 +107,7 @@ void HIGHSCORES_ReloadList(){
|
|||||||
char * name, * scorestring;
|
char * name, * scorestring;
|
||||||
int nameCharCount = 0, scoreCharCount = 0;
|
int nameCharCount = 0, scoreCharCount = 0;
|
||||||
bool switchread = false;
|
bool switchread = false;
|
||||||
ul = malloc(10 * sizeof(User));
|
HIGHSCORES_UserList = malloc(10 * sizeof(User));
|
||||||
fp = fopen("output.txt", "r");
|
fp = fopen("output.txt", "r");
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
return;
|
return;
|
||||||
@ -141,7 +141,7 @@ void HIGHSCORES_ReloadList(){
|
|||||||
User tmp;
|
User tmp;
|
||||||
strcpy(tmp.Username, name);
|
strcpy(tmp.Username, name);
|
||||||
strcpy(tmp.Score, scorestring);
|
strcpy(tmp.Score, scorestring);
|
||||||
ul[counter++] = tmp;
|
HIGHSCORES_UserList[counter++] = tmp;
|
||||||
}
|
}
|
||||||
free(name);
|
free(name);
|
||||||
free(scorestring);
|
free(scorestring);
|
||||||
@ -150,9 +150,9 @@ void HIGHSCORES_ReloadList(){
|
|||||||
if (line)
|
if (line)
|
||||||
free(line);
|
free(line);
|
||||||
for (size_t i = 0; i < counter; i++) {
|
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;
|
HIGHSCORES_EntriesGot = counter;
|
||||||
printf("BHI Interface successfully quit!\n");
|
printf("BHI Interface successfHIGHSCORES_UserListly quit!\n");
|
||||||
} /* main */
|
} /* main */
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include "gamestate.h"
|
#include "gamestate.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
SDL_Texture * TITLE_Texture;
|
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_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, TITLE_Texture, NULL, &TITLE_Rect);
|
||||||
|
Loading…
Reference in New Issue
Block a user