From 296a184b4a102a5224a0c7cb209b111cbbc482a6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 22 Jun 2023 22:58:22 +0100 Subject: Game over screen Also move private defines to the game module. --- src/game.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/game.h | 11 ----------- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/game.c b/src/game.c index 76969ae..4c1d55b 100644 --- a/src/game.c +++ b/src/game.c @@ -12,6 +12,19 @@ #include "game.h" +#define GAME_LIVES_START 3 +#define GAME_LIVES_MAX 9 +#define GAME_TIME_MAX 60 + +#define HUD_CLEAN 0 +#define HUD_LIVES 1 +#define HUD_SCORE 2 +#define HUD_STAGE 4 +#define HUD_TIME 8 +#define HUD_ALL 255 + +#define GAMEOVER_DELAY 96 + static uint32_t hiscore = 15000; static uint8_t hud; @@ -23,6 +36,7 @@ static uint32_t score; static uint8_t stage; static uint8_t gold; static uint8_t time; +static uint8_t gameover; static void hud_render() { @@ -67,6 +81,24 @@ static void hud_render() hud = HUD_CLEAN; } +static void run_gameover() +{ + blit_erase(0); + + /* restore the HUD after erasing the screen */ + hud = HUD_ALL; + hud_render(); + + put_text(124, 90, "GAME OVER", 1); + + wait_vsync(); + blit_update(); + + /* wait some time */ + for (uint8_t i = 0; i < 255; i++) + wait_vsync(); +} + void run_game() { lives = GAME_LIVES_START; @@ -105,6 +137,16 @@ void run_game() wait_vsync(); blit_update(); + + if (gameover) + { + gameover--; + if (gameover == 1) + { + run_gameover(); + break; + } + } } /* wait for ESC to be release */ @@ -126,6 +168,13 @@ uint32_t get_hiscore() uint8_t dec_lives() { lives--; + + if (lives == 0) + { + gameover = GAMEOVER_DELAY; + timer_stop(); + } + hud |= HUD_LIVES; return lives; } diff --git a/src/game.h b/src/game.h index a13bdb9..3058018 100644 --- a/src/game.h +++ b/src/game.h @@ -1,17 +1,6 @@ #ifndef _GAME_H #define _GAME_H -#define GAME_LIVES_START 3 -#define GAME_LIVES_MAX 9 -#define GAME_TIME_MAX 60 - -#define HUD_CLEAN 0 -#define HUD_LIVES 1 -#define HUD_SCORE 2 -#define HUD_STAGE 4 -#define HUD_TIME 8 -#define HUD_ALL 255 - void run_game(); void add_score(uint8_t v); uint32_t get_hiscore(); -- cgit v1.2.3