aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-29 22:18:17 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-29 22:18:17 +0100
commit623b1dfa54e77d3ca21fb64e200a32ee9a61c021 (patch)
tree85f09d8e3a74e56458bfb5c7a2b1a552d2506305
parent10f11bb551897abc5f6978b3a6ee1b373b9341d2 (diff)
downloadgold-mine-run-623b1dfa54e77d3ca21fb64e200a32ee9a61c021.tar.gz
gold-mine-run-623b1dfa54e77d3ca21fb64e200a32ee9a61c021.zip
Add pause / resume
-rw-r--r--README.md10
-rw-r--r--TODO.md1
-rw-r--r--src/game.c22
3 files changed, 32 insertions, 1 deletions
diff --git a/README.md b/README.md
index a5a758d..867195a 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,16 @@ Running the game:
- 386 or later
- Some RAM! (TBD)
+The game can be controlled by keyboard.
+
+| Key | Action |
+| --- | --- |
+| Cursor up | Jump |
+| Cursor left | Move left |
+| Cursor right | Move Right |
+| P | Pause / resume game |
+| ESC | Exit the game |
+
Development:
- GNU Make
diff --git a/TODO.md b/TODO.md
index cbe486c..8ccd4df 100644
--- a/TODO.md
+++ b/TODO.md
@@ -10,7 +10,6 @@
- sound
- libmikmod
- screens
- - pause
- intro, new game
- input
- joystick?
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();