From a1de326ac5d89cbf9555c9a0a9a662af35c6dcf7 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 15 Jun 2023 22:58:30 +0100 Subject: Implement a countdown clock in the timer Updated the HUD to show the time. --- src/game.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 70c3235..b49e859 100644 --- a/src/game.c +++ b/src/game.c @@ -12,12 +12,14 @@ static uint32_t hiscore = 15000; static uint8_t hud; +static volatile uint8_t clock_updated; /* game variables */ static uint8_t lives; static uint32_t score; static uint8_t stage; static uint8_t gold; +static uint8_t time; void hud_render() { @@ -49,7 +51,7 @@ void hud_render() if (hud & HUD_TIME) { - sprintf(b, "%02d", 0); + sprintf(b, "%02d", time); put_text(172, 4, b); } @@ -68,14 +70,23 @@ void run_game() score = 0; stage = 0; gold = 30; + time = GAME_TIME_MAX; hud = HUD_ALL; map_init(binary_stage_start); map_render(); + timer_start(GAME_TIME_MAX, &clock_updated); + while (!keys[KEY_ESC]) { + if (clock_updated) + { + time = timer_value(); + hud |= HUD_TIME; + } + if (hud) hud_render(); -- cgit v1.2.3