Merge branch 'dev' of collaborating.tuhh.de:czg6669/breakout into dev
This commit is contained in:
commit
f2ce6658e9
25
highscores.c
25
highscores.c
@ -16,14 +16,15 @@ SDL_Color HIGHSCORES_FontColor;
|
|||||||
SDL_Texture * HIGHSCORES_TableTexture;
|
SDL_Texture * HIGHSCORES_TableTexture;
|
||||||
SDL_Rect HIGHSCORES_TotalRect;
|
SDL_Rect HIGHSCORES_TotalRect;
|
||||||
TTF_Font * HIGHSCORES_FontFamily = NULL;
|
TTF_Font * HIGHSCORES_FontFamily = NULL;
|
||||||
|
SDL_Surface * tempSurface;
|
||||||
|
|
||||||
void HIGHSCORES_Initialize(){
|
void HIGHSCORES_Initialize(){
|
||||||
printf("Initializing Highscores...\n");
|
printf("Initializing Highscores...\n");
|
||||||
HIGHSCORES_FontColor = (SDL_Color) {255, 255, 255 };
|
HIGHSCORES_FontColor = (SDL_Color) {255, 255, 255 };
|
||||||
HIGHSCORES_UserList = malloc(10 * sizeof(User));
|
HIGHSCORES_UserList = malloc(10 * sizeof(User));
|
||||||
HIGHSCORES_FontFamily = TTF_OpenFont(HIGHSCORES_FontFile, 48);
|
HIGHSCORES_FontFamily = TTF_OpenFont(HIGHSCORES_FontFile, 48);
|
||||||
if (!HIGHSCORES_FontFamily) printf("Font coHIGHSCORES_UserListd not initialize! Error: %s\n", TTF_GetError());
|
if (!HIGHSCORES_FontFamily) printf("Font could not initialize! Error: %s\n", TTF_GetError());
|
||||||
else printf("Font was successfHIGHSCORES_UserListly initialized!\n");
|
else printf("Font was successfully initialized!\n");
|
||||||
printFontStyle(HIGHSCORES_FontFamily);
|
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");
|
||||||
@ -58,6 +59,7 @@ void HIGHSCORES_Deinitialize(){
|
|||||||
TTF_CloseFont(HIGHSCORES_FontFamily);
|
TTF_CloseFont(HIGHSCORES_FontFamily);
|
||||||
HIGHSCORES_FontFamily = NULL; // to be safe...
|
HIGHSCORES_FontFamily = NULL; // to be safe...
|
||||||
SDL_DestroyTexture(HIGHSCORES_TableTexture);
|
SDL_DestroyTexture(HIGHSCORES_TableTexture);
|
||||||
|
SDL_FreeSurface(tempSurface);
|
||||||
free(HIGHSCORES_UserList);
|
free(HIGHSCORES_UserList);
|
||||||
printf("Highscores de-initialized!\n");
|
printf("Highscores de-initialized!\n");
|
||||||
}
|
}
|
||||||
@ -69,15 +71,20 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
|
|||||||
SDL_Rect Message_rect;
|
SDL_Rect Message_rect;
|
||||||
SDL_Surface * HIGHSCORES_TableSurface = SDL_CreateRGBSurface(0, 1920, 1080, 32, 0, 0, 0, 0);
|
SDL_Surface * HIGHSCORES_TableSurface = SDL_CreateRGBSurface(0, 1920, 1080, 32, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
if (!HIGHSCORES_TableSurface) {
|
||||||
|
printf("Surface wasn't created!\n");
|
||||||
|
}
|
||||||
sprintf(buffer, format, "Username", "Score");
|
sprintf(buffer, format, "Username", "Score");
|
||||||
SDL_Surface * tempSurface = HIGHSCORES_DrawText(buffer, &Message_rect);
|
HIGHSCORES_DrawText(buffer, &Message_rect);
|
||||||
Message_rect.y = 70;
|
Message_rect.y = 70;
|
||||||
Message_rect.x = 50;
|
Message_rect.x = 50;
|
||||||
|
Message_rect.h = 50;
|
||||||
|
Message_rect.w = 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 < HIGHSCORES_EntriesGot) {
|
while (count < HIGHSCORES_EntriesGot) {
|
||||||
sprintf(buffer, format, HIGHSCORES_UserList[count].Username, HIGHSCORES_UserList[count].Score);
|
sprintf(buffer, format, HIGHSCORES_UserList[count].Username, HIGHSCORES_UserList[count].Score);
|
||||||
tempSurface = HIGHSCORES_DrawText(buffer, &Message_rect);
|
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;
|
||||||
SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect);
|
SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect);
|
||||||
@ -85,13 +92,15 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
HIGHSCORES_TableTexture = SDL_CreateTextureFromSurface(renderer, HIGHSCORES_TableSurface);
|
HIGHSCORES_TableTexture = SDL_CreateTextureFromSurface(renderer, HIGHSCORES_TableSurface);
|
||||||
|
if (!HIGHSCORES_TableTexture) {
|
||||||
|
printf("Texture wasn't created!\n");
|
||||||
|
}
|
||||||
SDL_FreeSurface(HIGHSCORES_TableSurface);
|
SDL_FreeSurface(HIGHSCORES_TableSurface);
|
||||||
} /* HIGHSCORES_GenerateSurface */
|
} /* HIGHSCORES_GenerateSurface */
|
||||||
|
|
||||||
SDL_Surface * HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){
|
void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect){
|
||||||
TTF_SizeText(HIGHSCORES_FontFamily, text, &(Message_rect->w), &(Message_rect->h));
|
TTF_SizeText(HIGHSCORES_FontFamily, text, &(Message_rect->w), &(Message_rect->h));
|
||||||
SDL_Surface * tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
|
tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
|
||||||
return tempSurface;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HIGHSCORES_ReloadList(){
|
void HIGHSCORES_ReloadList(){
|
||||||
@ -154,5 +163,5 @@ void HIGHSCORES_ReloadList(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
HIGHSCORES_EntriesGot = counter;
|
HIGHSCORES_EntriesGot = counter;
|
||||||
printf("BHI Interface successfHIGHSCORES_UserListly quit!\n");
|
printf("BHI Interface successfully quit!\n");
|
||||||
} /* main */
|
} /* main */
|
||||||
|
@ -13,7 +13,7 @@ void printFontStyle(TTF_Font * ffont);
|
|||||||
void HIGHSCORES_Draw(SDL_Renderer * renderer);
|
void HIGHSCORES_Draw(SDL_Renderer * renderer);
|
||||||
void HIGHSCORES_Deinitialize();
|
void HIGHSCORES_Deinitialize();
|
||||||
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer);
|
void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer);
|
||||||
SDL_Surface * HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect);
|
void HIGHSCORES_DrawText(char * text, SDL_Rect * Message_rect);
|
||||||
void HIGHSCORES_ReloadList();
|
void HIGHSCORES_ReloadList();
|
||||||
// End Prototypes
|
// End Prototypes
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user