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
                 <tr><td>Start (Enter)</td><td>Pause</td></tr>
63
                 <tr><td>Start (Enter)</td><td>Pause</td></tr>
64
                 <tr><td>Select (V)</td><td>About</td></tr>
64
                 <tr><td>Select (V)</td><td>About</td></tr>
65
             </table>
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
             <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>
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
             <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>
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
             <hr>
69
             <hr>

+ 24
- 2
src/game.c View File

22
 #include <rand.h>
22
 #include <rand.h>
23
 #include <stdint.h>
23
 #include <stdint.h>
24
 
24
 
25
+#include "gb/gb.h"
25
 #include "maps.h"
26
 #include "maps.h"
26
 #include "obj.h"
27
 #include "obj.h"
27
 #include "sprites.h"
28
 #include "sprites.h"
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
         pos_x += spd_x;
323
         pos_x += spd_x;
301
         pos_y += spd_y;
324
         pos_y += spd_y;
302
         move_bkg(pos_x >> POS_SCALE_BG, pos_y >> POS_SCALE_BG);
325
         move_bkg(pos_x >> POS_SCALE_BG, pos_y >> POS_SCALE_BG);
303
 
326
 
304
         uint8_t hiwater = SPR_NUM_START;
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
             spr_ship(rot, acc & (ACC_X | ACC_Y), &hiwater);
330
             spr_ship(rot, acc & (ACC_X | ACC_Y), &hiwater);
309
             ship_hiwater = hiwater;
331
             ship_hiwater = hiwater;
310
         } else {
332
         } else {

+ 13
- 1
src/sprite_data.c View File

28
 #include "shoot.h"
28
 #include "shoot.h"
29
 #include "bar_spr8.h"
29
 #include "bar_spr8.h"
30
 #include "expl_spr16.h"
30
 #include "expl_spr16.h"
31
+#include "pause.h"
31
 
32
 
32
 BANKREF(power_palettes)
33
 BANKREF(power_palettes)
33
 
34
 
135
         .cnt = expl_spr16_TILE_COUNT,
136
         .cnt = expl_spr16_TILE_COUNT,
136
         .off = TILE_NUM_START,
137
         .off = TILE_NUM_START,
137
         .bank = BANK(expl_spr16),
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
     SPR_HEALTH,
35
     SPR_HEALTH,
36
     SPR_POWER,
36
     SPR_POWER,
37
     SPR_EXPL,
37
     SPR_EXPL,
38
+    SPR_PAUSE,
38
 
39
 
39
     SPRITE_COUNT
40
     SPRITE_COUNT
40
 };
41
 };

Loading…
Cancel
Save