Minor bugfix in gameover screen

This commit is contained in:
Michael Chen 2018-01-23 22:17:45 +01:00
parent 45221cb72b
commit c577dcc2d7
2 changed files with 24 additions and 20 deletions

View File

@ -37,15 +37,15 @@ extern int width, height;
float PADDLE_SmoothFactor = 0.1f; float PADDLE_SmoothFactor = 0.1f;
int BLOCK_TextureCount = 24; int BLOCK_TextureCount = 24;
int BALL_TextureCount = 9; int BALL_TextureCount = 9;
int GAME_CountdownTextureCount = 4; int BREAKOUT_CountdownTextureCount = 4;
int PADDLE_TextureCount = 9; int PADDLE_TextureCount = 9;
SDL_Texture * BALL_Texture; SDL_Texture * BALL_Texture;
SDL_Texture * GAME_CountdownTexture; SDL_Texture * BREAKOUT_CountdownTexture;
SDL_Texture * PADDLE_Texture; SDL_Texture * PADDLE_Texture;
SDL_Texture * BLOCK_Texture; SDL_Texture * BLOCK_Texture;
SDL_Texture * GAME_PausedTexture; SDL_Texture * BREAKOUT_PausedTexture;
SDL_Rect * BALL_SourceRects; SDL_Rect * BALL_SourceRects;
SDL_Rect * GAME_CountdownSourceRects; SDL_Rect * BREAKOUT_CountdownSourceRects;
SDL_Rect * PADDLE_SourceRects; SDL_Rect * PADDLE_SourceRects;
SDL_Rect * BLOCK_SourceRects; SDL_Rect * BLOCK_SourceRects;
Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys; Uint8 * PADDLE_MoveLeftKeys, * PADDLE_MoveRightKeys;
@ -61,17 +61,17 @@ void BREAKOUT_INITIALIZE(SDL_Renderer * renderer){
BALL_Initialize(renderer); BALL_Initialize(renderer);
PADDLE_Initialize(renderer); PADDLE_Initialize(renderer);
BLOCK_Initialize(renderer); BLOCK_Initialize(renderer);
GAME_CountdownTexture = IMG_LoadTexture(renderer, BRAEKOUT_CountdownTexturePath); BREAKOUT_CountdownTexture = IMG_LoadTexture(renderer, BRAEKOUT_CountdownTexturePath);
if (!GAME_CountdownTexture) printf("Countdown texture failed to load!\n"); if (!BREAKOUT_CountdownTexture) printf("Countdown texture failed to load!\n");
GAME_PausedTexture = IMG_LoadTexture(renderer, BRAEKOUT_PausedTexturePath); BREAKOUT_PausedTexture = IMG_LoadTexture(renderer, BRAEKOUT_PausedTexturePath);
if (!GAME_PausedTexture) printf("Paused texture failed to load!\n"); if (!BREAKOUT_PausedTexture) printf("Paused texture failed to load!\n");
GAME_CountdownTextureCount = 4; BREAKOUT_CountdownTextureCount = 4;
GAME_CountdownSourceRects = (SDL_Rect *)malloc(GAME_CountdownTextureCount * sizeof(SDL_Rect)); BREAKOUT_CountdownSourceRects = (SDL_Rect *)malloc(BREAKOUT_CountdownTextureCount * sizeof(SDL_Rect));
if (!GAME_CountdownSourceRects) printf("FATAL! Memory allocation failed!\n"); if (!BREAKOUT_CountdownSourceRects) printf("FATAL! Memory allocation failed!\n");
GAME_CountdownSourceRects[0] = (SDL_Rect) {.x = 1, .y = 668, .w = 1000, .h = 732 }; BREAKOUT_CountdownSourceRects[0] = (SDL_Rect) {.x = 1, .y = 668, .w = 1000, .h = 732 };
GAME_CountdownSourceRects[1] = (SDL_Rect) {.x = 1, .y = 1, .w = 242, .h = 665 }; BREAKOUT_CountdownSourceRects[1] = (SDL_Rect) {.x = 1, .y = 1, .w = 242, .h = 665 };
GAME_CountdownSourceRects[2] = (SDL_Rect) {.x = 245, .y = 1, .w = 443, .h = 665 }; BREAKOUT_CountdownSourceRects[2] = (SDL_Rect) {.x = 245, .y = 1, .w = 443, .h = 665 };
GAME_CountdownSourceRects[3] = (SDL_Rect) {.x = 690, .y = 1, .w = 443, .h = 665 }; BREAKOUT_CountdownSourceRects[3] = (SDL_Rect) {.x = 690, .y = 1, .w = 443, .h = 665 };
printf("Game initialized!\n"); printf("Game initialized!\n");
BREAKOUT_IsInit = true; BREAKOUT_IsInit = true;
} else printf("Game is already initialized!\n"); } else printf("Game is already initialized!\n");
@ -174,9 +174,9 @@ void BREAKOUT_Draw(Scenery * scenery, SDL_Renderer * renderer){
SCORE_DrawHUD(renderer, scenery); SCORE_DrawHUD(renderer, scenery);
BREAKOUT_DrawLivesHUD(renderer, scenery); BREAKOUT_DrawLivesHUD(renderer, scenery);
if (scenery->IsPaused) { if (scenery->IsPaused) {
TEXTURE_RenderCentered(renderer, GAME_PausedTexture, 0.5f); TEXTURE_RenderCentered(renderer, BREAKOUT_PausedTexture, 0.5f);
} else if ((scenery->StartCountdown) > 0) { // ! Render Z-Layer ! } else if ((scenery->StartCountdown) > 0) { // ! Render Z-Layer !
TEXTURE_RenderCenteredSpriteSheet(renderer, GAME_CountdownTexture, (GAME_CountdownSourceRects + (((scenery->StartCountdown) - 1) / 60)), 1.0f); TEXTURE_RenderCenteredSpriteSheet(renderer, BREAKOUT_CountdownTexture, (BREAKOUT_CountdownSourceRects + (((scenery->StartCountdown) - 1) / 60)), 1.0f);
} }
} }
@ -197,14 +197,14 @@ void BREAKOUT_DrawLivesHUD(SDL_Renderer * renderer, Scenery * scenery){
void BREAKOUT_DEINITIALIZE(){ void BREAKOUT_DEINITIALIZE(){
if (BREAKOUT_IsInit) { if (BREAKOUT_IsInit) {
printf("De-initializing Game...\n"); printf("De-initializing Game...\n");
SDL_DestroyTexture(GAME_CountdownTexture); SDL_DestroyTexture(BREAKOUT_CountdownTexture);
SDL_DestroyTexture(GAME_PausedTexture); SDL_DestroyTexture(BREAKOUT_PausedTexture);
free(PADDLE_MoveLeftKeys); free(PADDLE_MoveLeftKeys);
free(PADDLE_MoveRightKeys); free(PADDLE_MoveRightKeys);
free(BALL_SourceRects); free(BALL_SourceRects);
free(PADDLE_SourceRects); free(PADDLE_SourceRects);
free(BLOCK_SourceRects); free(BLOCK_SourceRects);
free(GAME_CountdownSourceRects); free(BREAKOUT_CountdownSourceRects);
BALL_Deinitialize(); BALL_Deinitialize();
PADDLE_Deinitialize(); PADDLE_Deinitialize();
BLOCK_Deinitialize(); BLOCK_Deinitialize();

View File

@ -112,6 +112,10 @@ void GAMEOVER_GetDigits(int input, int * digitCount){
GAMEOVER_Digits[(count++)] = (score % 10); GAMEOVER_Digits[(count++)] = (score % 10);
score /= 10; score /= 10;
} }
if (count == 0) {
count = 1;
GAMEOVER_Digits[0] = 0;
}
*digitCount = count; *digitCount = count;
} }