aboutsummaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-22 22:58:22 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-22 22:58:22 +0100
commit296a184b4a102a5224a0c7cb209b111cbbc482a6 (patch)
treebff7a8b90e2532c389f5e3de6f2bb52d7c97c779 /src/game.c
parent8524301a3c4348a8efd608f39dd4a9fd1991e775 (diff)
downloadgold-mine-run-296a184b4a102a5224a0c7cb209b111cbbc482a6.tar.gz
gold-mine-run-296a184b4a102a5224a0c7cb209b111cbbc482a6.zip
Game over screen
Also move private defines to the game module.
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c49
1 files changed, 49 insertions, 0 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;
}