aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-08-06 20:36:07 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-08-06 20:36:07 +0100
commitb76ba4c6eeab4c9e4f77fa1f6f81cdec3f9ff025 (patch)
tree89c1aabc43d6a8bd687ce4c8e9f635bd2114571b
parentf7e027a1da1f44c1ef68f0532f797343e7212073 (diff)
downloadgold-mine-run-b76ba4c6eeab4c9e4f77fa1f6f81cdec3f9ff025.tar.gz
gold-mine-run-b76ba4c6eeab4c9e4f77fa1f6f81cdec3f9ff025.zip
Ask for confirmation when abandoning the game
-rw-r--r--README.md2
-rw-r--r--src/game.c86
2 files changed, 82 insertions, 6 deletions
diff --git a/README.md b/README.md
index 47280dc..95921b9 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ The game can be controlled by keyboard or joystick.
| Cursor right | Joystick right | Move Right |
| Z | Button 1 | Jump |
| P | - | Pause / resume game |
-| ESC | - | Exit the game |
+| ESC | - | Abandon / exit the game |
Check `-h` CLI flag for options.
diff --git a/src/game.c b/src/game.c
index 2d41821..c2420ca 100644
--- a/src/game.c
+++ b/src/game.c
@@ -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)