diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-08-06 20:36:07 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-08-06 20:36:07 +0100 |
commit | b76ba4c6eeab4c9e4f77fa1f6f81cdec3f9ff025 (patch) | |
tree | 89c1aabc43d6a8bd687ce4c8e9f635bd2114571b /src/game.c | |
parent | f7e027a1da1f44c1ef68f0532f797343e7212073 (diff) | |
download | gold-mine-run-b76ba4c6eeab4c9e4f77fa1f6f81cdec3f9ff025.tar.gz gold-mine-run-b76ba4c6eeab4c9e4f77fa1f6f81cdec3f9ff025.zip |
Ask for confirmation when abandoning the game
Diffstat (limited to 'src/game.c')
-rw-r--r-- | src/game.c | 86 |
1 files changed, 81 insertions, 5 deletions
@@ -3,6 +3,7 @@ #include <dos.h> #include "keyb.h" +#include "control.h" #include "vga.h" #include "sound.h" #include "text.h" @@ -333,6 +334,79 @@ static void run_stageclear() wait_frames(64); } +static uint8_t run_confirm_quit() +{ + timer_stop(); + + blit_target(TARGET_BUFFER); + blit_erase(0); + + hud = HUD_ALL; + hud_render(); + put_text(108, 90, "ABANDON GAME?", 1); + + wait_vsync(); + blit_copy_all(); + + blit_target(TARGET_SCREEN); + + uint8_t sel = 0; + uint8_t ctl = CTL_NONE; + uint8_t cooldown = 0; + +update_menu: + wait_vsync(); + if (sel) + { + put_text(144, 105, " YES", 4); + put_text(144, 115, ">NO", 5); + } + else + { + put_text(144, 105, ">YES", 5); + put_text(144, 115, " NO", 4); + } + + while (1) + { + if (cooldown) + cooldown--; + else + { + ctl = control_read(); + + if ((ctl & CTL_UP) || (ctl & CTL_DOWN)) + { + cooldown = 10; + sel ^= 1; + goto update_menu; + } + + if (keys[KEY_ENTER]) + break; + } + + wait_vsync(); + } + + /* restore the game screen only when not abandoned */ + if (sel) + { + blit_target(TARGET_BUFFER); + map_render(); + wait_vsync(); + blit_copy_all(); + + blit_target(TARGET_SCREEN); + wait_vsync(); + entities_draw(); + } + + timer_resume(); + + return sel == 0; +} + void run_game() { continuegame = 0; @@ -389,7 +463,7 @@ next_stage: sound_music_pattern(PAT_PLAY); - while (!keys[KEY_ESC]) + while (1) { if (clock_updated) { @@ -400,6 +474,12 @@ next_stage: if (hud) hud_render(); + if (keys[KEY_ESC]) + { + if (run_confirm_quit()) + break; + } + if (keys[KEY_P]) { /* pause / resume */ @@ -505,10 +585,6 @@ next_stage: } sound_music_pattern(PAT_SILENCE); - - /* wait for ESC to be release */ - while (keys[KEY_ESC]) - wait_vsync(); } void add_score(uint8_t v) |