Merge branch 'dev' of collaborating.tuhh.de:czg6669/breakout into dev

This commit is contained in:
Andreas Neumann 2018-01-18 16:12:04 +01:00
commit f2ce6658e9
2 changed files with 18 additions and 9 deletions

View File

@ -16,14 +16,15 @@ SDL_Color HIGHSCORES_FontColor;
SDL_Texture * HIGHSCORES_TableTexture;
SDL_Rect HIGHSCORES_TotalRect;
TTF_Font * HIGHSCORES_FontFamily = NULL;
SDL_Surface * tempSurface;
void HIGHSCORES_Initialize(){
printf("Initializing Highscores...\n");
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");
if (!HIGHSCORES_FontFamily) printf("Font could not initialize! Error: %s\n", TTF_GetError());
else printf("Font was successfully initialized!\n");
printFontStyle(HIGHSCORES_FontFamily);
HIGHSCORES_TotalRect = (SDL_Rect) {.x = 0, .y = 0, .w = 1920, .h = 1080 };
printf("Highscores initialized!\n");
@ -58,6 +59,7 @@ void HIGHSCORES_Deinitialize(){
TTF_CloseFont(HIGHSCORES_FontFamily);
HIGHSCORES_FontFamily = NULL; // to be safe...
SDL_DestroyTexture(HIGHSCORES_TableTexture);
SDL_FreeSurface(tempSurface);
free(HIGHSCORES_UserList);
printf("Highscores de-initialized!\n");
}
@ -69,15 +71,20 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
SDL_Rect Message_rect;
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");
SDL_Surface * tempSurface = HIGHSCORES_DrawText(buffer, &Message_rect);
HIGHSCORES_DrawText(buffer, &Message_rect);
Message_rect.y = 70;
Message_rect.x = 50;
Message_rect.h = 50;
Message_rect.w = 50;
SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect);
SDL_FreeSurface(tempSurface);
while (count < HIGHSCORES_EntriesGot) {
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.x = 50;
SDL_BlitSurface(tempSurface, NULL, HIGHSCORES_TableSurface, &Message_rect);
@ -85,13 +92,15 @@ void HIGHSCORES_GenerateTexture(SDL_Renderer * renderer){
count++;
}
HIGHSCORES_TableTexture = SDL_CreateTextureFromSurface(renderer, HIGHSCORES_TableSurface);
if (!HIGHSCORES_TableTexture) {
printf("Texture wasn't created!\n");
}
SDL_FreeSurface(HIGHSCORES_TableSurface);
} /* 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));
SDL_Surface * tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
return tempSurface;
tempSurface = TTF_RenderText_Solid(HIGHSCORES_FontFamily, text, HIGHSCORES_FontColor);
}
void HIGHSCORES_ReloadList(){
@ -154,5 +163,5 @@ void HIGHSCORES_ReloadList(){
}
HIGHSCORES_EntriesGot = counter;
printf("BHI Interface successfHIGHSCORES_UserListly quit!\n");
printf("BHI Interface successfully quit!\n");
} /* main */

View File

@ -13,7 +13,7 @@ void printFontStyle(TTF_Font * ffont);
void HIGHSCORES_Draw(SDL_Renderer * renderer);
void HIGHSCORES_Deinitialize();
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();
// End Prototypes