Browse Source

add heal and damage sfx

Thomas B 2 weeks ago
parent
commit
0bec135ae0
10 changed files with 97 additions and 54 deletions
  1. 2
    0
      README.md
  2. BIN
      data/sfx_damage.wav
  3. BIN
      data/sfx_heal.wav
  4. 10
    1
      src/game.c
  5. 14
    0
      src/sample.c
  6. 4
    0
      src/sample.h
  7. 4
    0
      src/sound_game.c
  8. 6
    0
      src/sound_menu.c
  9. 6
    0
      src/sound_over.c
  10. 51
    53
      src/sprites.c

+ 2
- 0
README.md View File

68
 
68
 
69
 Unfortunately you will have to edit the hard-coded paths in `.vscode/launch.json`, I haven't been able to use variables there for some reason.
69
 Unfortunately you will have to edit the hard-coded paths in `.vscode/launch.json`, I haven't been able to use variables there for some reason.
70
 
70
 
71
+For hard debugging cases the reverse stepping feature of the debugger in [GameRoy](https://github.com/Rodrigodd/gameroy) may come in handy.
72
+
71
 ## License
73
 ## License
72
 
74
 
73
 The source code of this Duality GameBoy clone is licensed as GPLv3.
75
 The source code of this Duality GameBoy clone is licensed as GPLv3.

BIN
data/sfx_damage.wav View File


BIN
data/sfx_heal.wav View File


+ 10
- 1
src/game.c View File

512
 
512
 
513
             if (health > damage) {
513
             if (health > damage) {
514
                 health -= damage;
514
                 health -= damage;
515
+                if ((!sample_running()) && (sample_last() != SFX_DAMAGE)) {
516
+                    sample_play(SFX_DAMAGE);
517
+                }
515
             } else if (health <= damage) {
518
             } else if (health <= damage) {
516
                 health = 0;
519
                 health = 0;
517
                 show_explosion(power);
520
                 show_explosion(power);
518
                 break;
521
                 break;
519
             }
522
             }
520
-        } else if (damage < 0) {
523
+        } else if ((damage < 0) && (health < HEALTH_MAX)) {
524
+            if ((!sample_running()) && (sample_last() != SFX_HEAL)) {
525
+                sample_play(SFX_HEAL);
526
+            }
527
+
521
             health += -damage;
528
             health += -damage;
522
             if (health > HEALTH_MAX) {
529
             if (health > HEALTH_MAX) {
523
                 health = HEALTH_MAX;
530
                 health = HEALTH_MAX;
524
             }
531
             }
532
+        } else if (damage == 0) {
533
+            sample_last_reset();
525
         }
534
         }
526
 
535
 
527
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
536
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);

+ 14
- 0
src/sample.c View File

29
 #include "sfx_shoot.h"
29
 #include "sfx_shoot.h"
30
 #include "sfx_expl_orb.h"
30
 #include "sfx_expl_orb.h"
31
 #include "sfx_expl_ship.h"
31
 #include "sfx_expl_ship.h"
32
+#include "sfx_damage.h"
33
+#include "sfx_heal.h"
32
 #include "sample.h"
34
 #include "sample.h"
33
 
35
 
34
 BANKREF(sample)
36
 BANKREF(sample)
35
 
37
 
38
+static enum SFXS play_sfx = SFX_COUNT;
36
 static uint8_t play_bank = 1;
39
 static uint8_t play_bank = 1;
37
 static const uint8_t *play_sample = 0;
40
 static const uint8_t *play_sample = 0;
38
 static uint16_t play_length = 0;
41
 static uint16_t play_length = 0;
47
     { .bank = BANK(sfx_shoot),     .smp = sfx_shoot,     .len = sfx_shoot_SIZE >> 4 },     // SFX_SHOT
50
     { .bank = BANK(sfx_shoot),     .smp = sfx_shoot,     .len = sfx_shoot_SIZE >> 4 },     // SFX_SHOT
48
     { .bank = BANK(sfx_expl_orb),  .smp = sfx_expl_orb,  .len = sfx_expl_orb_SIZE >> 4 },  // SFX_EXPL_ORB
51
     { .bank = BANK(sfx_expl_orb),  .smp = sfx_expl_orb,  .len = sfx_expl_orb_SIZE >> 4 },  // SFX_EXPL_ORB
49
     { .bank = BANK(sfx_expl_ship), .smp = sfx_expl_ship, .len = sfx_expl_ship_SIZE >> 4 }, // SFX_EXPL_SHIP
52
     { .bank = BANK(sfx_expl_ship), .smp = sfx_expl_ship, .len = sfx_expl_ship_SIZE >> 4 }, // SFX_EXPL_SHIP
53
+    { .bank = BANK(sfx_damage),    .smp = sfx_damage,    .len = sfx_damage_SIZE >> 4 },    // SFX_DAMAGE
54
+    { .bank = BANK(sfx_heal),      .smp = sfx_heal,      .len = sfx_heal_SIZE >> 4 },      // SFX_HEAL
50
 };
55
 };
51
 
56
 
52
 void sample_play(enum SFXS sfx) BANKED {
57
 void sample_play(enum SFXS sfx) BANKED {
61
     */
66
     */
62
 
67
 
63
     CRITICAL {
68
     CRITICAL {
69
+        play_sfx = sfx;
64
         play_bank = sfxs[sfx].bank;
70
         play_bank = sfxs[sfx].bank;
65
         play_sample = sfxs[sfx].smp;
71
         play_sample = sfxs[sfx].smp;
66
         play_length = sfxs[sfx].len;
72
         play_length = sfxs[sfx].len;
71
     return (play_length > 0) ? 1 : 0;
77
     return (play_length > 0) ? 1 : 0;
72
 }
78
 }
73
 
79
 
80
+enum SFXS sample_last(void) BANKED {
81
+    return play_sfx;
82
+}
83
+
84
+void sample_last_reset(void) BANKED {
85
+    play_sfx = SFX_COUNT;
86
+}
87
+
74
 #if 1
88
 #if 1
75
 
89
 
76
 // TODO C version has a slight 'beep' always? and much worse at lower volumes?
90
 // TODO C version has a slight 'beep' always? and much worse at lower volumes?

+ 4
- 0
src/sample.h View File

26
     SFX_SHOT = 0,
26
     SFX_SHOT = 0,
27
     SFX_EXPL_ORB,
27
     SFX_EXPL_ORB,
28
     SFX_EXPL_SHIP,
28
     SFX_EXPL_SHIP,
29
+    SFX_DAMAGE,
30
+    SFX_HEAL,
29
 
31
 
30
     SFX_COUNT
32
     SFX_COUNT
31
 };
33
 };
32
 
34
 
33
 void sample_play(enum SFXS sfx) BANKED;
35
 void sample_play(enum SFXS sfx) BANKED;
34
 uint8_t sample_running(void) BANKED;
36
 uint8_t sample_running(void) BANKED;
37
+enum SFXS sample_last(void) BANKED;
38
+void sample_last_reset(void) BANKED;
35
 
39
 
36
 void sample_isr(void);
40
 void sample_isr(void);
37
 
41
 

+ 4
- 0
src/sound_game.c View File

23
  * See <http://www.gnu.org/licenses/>.
23
  * See <http://www.gnu.org/licenses/>.
24
  */
24
  */
25
 
25
 
26
+#include <assert.h>
27
+
26
 #include "banks.h"
28
 #include "banks.h"
27
 #include "sound_game.h"
29
 #include "sound_game.h"
28
 
30
 
70
     dEND
72
     dEND
71
 };
73
 };
72
 
74
 
75
+static_assert(sizeof(game_music) == sizeof(game_drums), "music loops need to be same length");
76
+
73
 const struct music music_game = {
77
 const struct music music_game = {
74
     .notes = game_music,
78
     .notes = game_music,
75
     .notes2 = NULL,
79
     .notes2 = NULL,

+ 6
- 0
src/sound_menu.c View File

23
  * See <http://www.gnu.org/licenses/>.
23
  * See <http://www.gnu.org/licenses/>.
24
  */
24
  */
25
 
25
 
26
+#include <assert.h>
27
+
26
 #include "banks.h"
28
 #include "banks.h"
27
 #include "sound_menu.h"
29
 #include "sound_menu.h"
28
 
30
 
258
     dEND
260
     dEND
259
 };
261
 };
260
 
262
 
263
+static_assert(sizeof(menu_music)  == sizeof(menu_music2), "music loops need to be same length");
264
+static_assert(sizeof(menu_music2) == sizeof(menu_drums),  "music loops need to be same length");
265
+static_assert(sizeof(menu_music)  == sizeof(menu_drums),  "music loops need to be same length");
266
+
261
 const struct music music_menu = {
267
 const struct music music_menu = {
262
     .notes = menu_music,
268
     .notes = menu_music,
263
     .notes2 = menu_music2,
269
     .notes2 = menu_music2,

+ 6
- 0
src/sound_over.c View File

23
  * See <http://www.gnu.org/licenses/>.
23
  * See <http://www.gnu.org/licenses/>.
24
  */
24
  */
25
 
25
 
26
+#include <assert.h>
27
+
26
 #include "banks.h"
28
 #include "banks.h"
27
 #include "sound.h"
29
 #include "sound.h"
28
 #include "sound_over.h"
30
 #include "sound_over.h"
193
     dEND
195
     dEND
194
 };
196
 };
195
 
197
 
198
+static_assert(sizeof(over_notes)  == sizeof(over_notes2), "music loops need to be same length");
199
+static_assert(sizeof(over_notes2) == sizeof(over_drums),  "music loops need to be same length");
200
+static_assert(sizeof(over_notes)  == sizeof(over_drums),  "music loops need to be same length");
201
+
196
 const struct music music_over = {
202
 const struct music music_over = {
197
     .notes = over_notes,
203
     .notes = over_notes,
198
     .notes2 = over_notes2,
204
     .notes2 = over_notes2,

+ 51
- 53
src/sprites.c View File

65
     }
65
     }
66
 
66
 
67
     START_ROM_BANK(metasprites[sprite].bank) {
67
     START_ROM_BANK(metasprites[sprite].bank) {
68
+        if (frame >= metasprites[sprite].ms_n) {
69
+            frame = 0;
70
+        }
68
 
71
 
69
-    if (frame >= metasprites[sprite].ms_n) {
70
-        frame = 0;
71
-    }
72
+        uint8_t pa_off = 0;
72
 
73
 
73
-    uint8_t pa_off = 0;
74
+        if (_cpu == CGB_TYPE) {
75
+            if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD) {
76
+                uint8_t pa_i = frame;
77
+                if (pa_i >= metasprites[sprite].pa_n) {
78
+                    pa_i = 0;
79
+                }
74
 
80
 
75
-    if (_cpu == CGB_TYPE) {
76
-        if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD) {
77
-            uint8_t pa_i = frame;
78
-            if (pa_i >= metasprites[sprite].pa_n) {
79
-                pa_i = 0;
80
-            }
81
+                set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS) + pa_i, 1, metasprites[sprite].pa + (pa_i * 4));
82
+            } else if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD_IP) {
83
+                pa_off = frame;
84
+                if (pa_off >= metasprites[sprite].pa_n) {
85
+                    pa_off = 0;
86
+                }
81
 
87
 
82
-            set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS) + pa_i, 1, metasprites[sprite].pa + (pa_i * 4));
83
-        } else if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD_IP) {
84
-            pa_off = frame;
85
-            if (pa_off >= metasprites[sprite].pa_n) {
86
-                pa_off = 0;
88
+                set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS), 1, metasprites[sprite].pa + (pa_off * 4));
87
             }
89
             }
88
-
89
-            set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS), 1, metasprites[sprite].pa + (pa_off * 4));
90
         }
90
         }
91
-    }
92
-
93
-    switch (flip) {
94
-        case FLIP_Y:
95
-            *hiwater += move_metasprite_flipy(
96
-                    metasprites[sprite].ms[frame], metasprites[sprite].off,
97
-                    (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
98
-                    DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
99
-                    DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
100
-            break;
101
-
102
-        case FLIP_XY:
103
-            *hiwater += move_metasprite_flipxy(
104
-                    metasprites[sprite].ms[frame], metasprites[sprite].off,
105
-                    (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
106
-                    DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
107
-                    DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
108
-            break;
109
-
110
-        case FLIP_X:
111
-            *hiwater += move_metasprite_flipx(
112
-                    metasprites[sprite].ms[frame], metasprites[sprite].off,
113
-                    (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
114
-                    DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
115
-                    DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
116
-            break;
117
-
118
-        case FLIP_NONE:
119
-        default:
120
-            *hiwater += move_metasprite_ex(
121
-                    metasprites[sprite].ms[frame], metasprites[sprite].off,
122
-                    (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
123
-                    DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
124
-                    DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
125
-            break;
126
-    }
127
 
91
 
92
+        switch (flip) {
93
+            case FLIP_Y:
94
+                *hiwater += move_metasprite_flipy(
95
+                        metasprites[sprite].ms[frame], metasprites[sprite].off,
96
+                        (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
97
+                        DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
98
+                        DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
99
+                break;
100
+
101
+            case FLIP_XY:
102
+                *hiwater += move_metasprite_flipxy(
103
+                        metasprites[sprite].ms[frame], metasprites[sprite].off,
104
+                        (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
105
+                        DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
106
+                        DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
107
+                break;
108
+
109
+            case FLIP_X:
110
+                *hiwater += move_metasprite_flipx(
111
+                        metasprites[sprite].ms[frame], metasprites[sprite].off,
112
+                        (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
113
+                        DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
114
+                        DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
115
+                break;
116
+
117
+            case FLIP_NONE:
118
+            default:
119
+                *hiwater += move_metasprite_ex(
120
+                        metasprites[sprite].ms[frame], metasprites[sprite].off,
121
+                        (metasprites[sprite].pa_i - pa_off) & PALETTE_NO_FLAGS, *hiwater,
122
+                        DEVICE_SPRITE_PX_OFFSET_X + (DEVICE_SCREEN_PX_WIDTH / 2) + x_off,
123
+                        DEVICE_SPRITE_PX_OFFSET_Y + (DEVICE_SCREEN_PX_HEIGHT / 2) + y_off);
124
+                break;
125
+        }
128
     } END_ROM_BANK
126
     } END_ROM_BANK
129
 }
127
 }
130
 
128
 

Loading…
Cancel
Save