From 623b1dfa54e77d3ca21fb64e200a32ee9a61c021 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 29 Jun 2023 22:18:17 +0100 Subject: Add pause / resume --- src/game.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 4441cf0..0113fe1 100644 --- a/src/game.c +++ b/src/game.c @@ -40,6 +40,7 @@ static uint8_t stage; static uint8_t time; static uint8_t pickaxe; static uint8_t gameover; +static uint8_t pause; static void wait_time(uint16_t frames) { @@ -121,6 +122,9 @@ static void run_gameover() void run_game() { + pause = 0; + gameover = 0; + lives = GAME_LIVES_START; score = 0; stage = 0; @@ -164,6 +168,24 @@ void run_game() if (hud) hud_render(); + if (keys[KEY_P]) + { + /* pause / resume */ + pause ^= 1; + + /* wait for the key to be released */ + while (keys[KEY_P]) + wait_vsync(); + + if (pause) + timer_stop(); + else + timer_resume(); + } + + if (pause) + continue; + /* erase first the last we draw */ player_erase(); entities_erase(); -- cgit v1.2.3