Browse Source

add pause and quit

Thomas B 1 month ago
parent
commit
2d6b8aa88d
5 changed files with 39 additions and 4 deletions
  1. BIN
      data/pause.png
  2. 1
    1
      docs/index.html
  3. 24
    2
      src/game.c
  4. 13
    1
      src/sprite_data.c
  5. 1
    0
      src/sprites.h

BIN
data/pause.png View File


+ 1
- 1
docs/index.html View File

@@ -63,7 +63,7 @@
63 63
                 <tr><td>Start (Enter)</td><td>Pause</td></tr>
64 64
                 <tr><td>Select (V)</td><td>About</td></tr>
65 65
             </table>
66
-            <p>Press Left or Right on the title screen to show either the black or white highscores. Press Select to show the about screen and build info.</p>
66
+            <p>Press Left or Right on the title screen to show either the black or white highscores. Press Select to show the about screen and build info. In-game press Start to pause and resume. While paused press Select to return to the menu.</p>
67 67
             <p>Collect small white spheres to get +5 white score. Collect small black spheres to get +5 black score. The opposite color will reduce your score when collected. Large black holes will attract you and damage your ship when touched. Large white spheres will repel you and replenish your health when touched. Accelerating will reduce your fuel, which will recharge when not accelerating. You can shoot large spheres for +10 points.<p>
68 68
             <p>For a more detailed description of the original game check out the <a href="https://gta.fandom.com/wiki/Duality">Duality article on GTA Wiki</a>.</p>
69 69
             <hr>

+ 24
- 2
src/game.c View File

@@ -22,6 +22,7 @@
22 22
 #include <rand.h>
23 23
 #include <stdint.h>
24 24
 
25
+#include "gb/gb.h"
25 26
 #include "maps.h"
26 27
 #include "obj.h"
27 28
 #include "sprites.h"
@@ -297,14 +298,35 @@ int32_t game(void) NONBANKED {
297 298
             }
298 299
         }
299 300
 
301
+        // re-draw ship sprite when we've just rotated or are starting or stopping acceleration
302
+        uint8_t redraw = (acc & ACC_R) || ((prev_acc & (ACC_X | ACC_Y)) != (acc & (ACC_X | ACC_Y)));
303
+
304
+        if (key_pressed(J_START)) {
305
+            uint8_t hiwater = SPR_NUM_START;
306
+            spr_draw(SPR_PAUSE, FLIP_NONE, 0, 0, 0, &hiwater);
307
+            hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
308
+
309
+            while (1) {
310
+                key_read();
311
+                if (key_pressed(J_START)) {
312
+                    break;
313
+                } else if (key_pressed(J_SELECT)) {
314
+                    return score;
315
+                }
316
+                vsync();
317
+            }
318
+
319
+            // re-draw ship sprite
320
+            redraw = 1;
321
+        }
322
+
300 323
         pos_x += spd_x;
301 324
         pos_y += spd_y;
302 325
         move_bkg(pos_x >> POS_SCALE_BG, pos_y >> POS_SCALE_BG);
303 326
 
304 327
         uint8_t hiwater = SPR_NUM_START;
305 328
 
306
-        // re-draw ship sprite when we've just rotated or are starting or stopping acceleration
307
-        if ((acc & ACC_R) || ((prev_acc & (ACC_X | ACC_Y)) != (acc & (ACC_X | ACC_Y)))) {
329
+        if (redraw) {
308 330
             spr_ship(rot, acc & (ACC_X | ACC_Y), &hiwater);
309 331
             ship_hiwater = hiwater;
310 332
         } else {

+ 13
- 1
src/sprite_data.c View File

@@ -28,6 +28,7 @@
28 28
 #include "shoot.h"
29 29
 #include "bar_spr8.h"
30 30
 #include "expl_spr16.h"
31
+#include "pause.h"
31 32
 
32 33
 BANKREF(power_palettes)
33 34
 
@@ -135,5 +136,16 @@ struct sprites metasprites[SPRITE_COUNT] = {
135 136
         .cnt = expl_spr16_TILE_COUNT,
136 137
         .off = TILE_NUM_START,
137 138
         .bank = BANK(expl_spr16),
138
-    }
139
+    },
140
+    { // SPR_PAUSE
141
+        .ms = pause_metasprites,
142
+        .ms_n = ARR_LEN(pause_metasprites),
143
+        .ti = pause_tiles,
144
+        .pa = pause_palettes,
145
+        .pa_n = pause_PALETTE_COUNT,
146
+        .pa_i = OAMF_CGB_PAL7,
147
+        .cnt = pause_TILE_COUNT,
148
+        .off = TILE_NUM_START,
149
+        .bank = BANK(pause),
150
+    },
139 151
 };

+ 1
- 0
src/sprites.h View File

@@ -35,6 +35,7 @@ enum SPRITES {
35 35
     SPR_HEALTH,
36 36
     SPR_POWER,
37 37
     SPR_EXPL,
38
+    SPR_PAUSE,
38 39
 
39 40
     SPRITE_COUNT
40 41
 };

Loading…
Cancel
Save