aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/sounds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdl/sounds.c')
-rw-r--r--src/sdl/sounds.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/sdl/sounds.c b/src/sdl/sounds.c
index f110b26..2c8c3f1 100644
--- a/src/sdl/sounds.c
+++ b/src/sdl/sounds.c
@@ -5,6 +5,21 @@
#define SOUND_OFS(asset_id) ((asset_id) - ASSET_SOUND_FIRST - 1)
+static const struct {
+ sound_t sound;
+ asset_id_t asset_id;
+} SOUND_MAP[] = {
+ { SOUND_BUMP, ASSET_SOUND_HIT_1_WAV },
+ { SOUND_LEVEL_DONE, ASSET_SOUND_POWERUP_3_WAV },
+ { SOUND_UNDO, ASSET_SOUND_HIT_1_WAV },
+ { SOUND_LEVEL_NEXT, ASSET_SOUND_POWERUP_1_WAV },
+ { SOUND_LEVEL_RESET, ASSET_SOUND_UNDO_0_WAV },
+ { SOUND_LEVEL_WARP, ASSET_SOUND_POWERUP_1_WAV },
+ { SOUND_SOLVE_CANCEL, ASSET_SOUND_HIT_2_WAV },
+ { SOUND_SOLVE_DONE, ASSET_SOUND_POWERUP_4_WAV },
+ { SOUND_LAST, ASSET_LAST },
+};
+
void
sounds_init(
Mix_Chunk ** const sounds
@@ -30,14 +45,37 @@ sounds_init(
}
}
+static asset_id_t
+get_asset_id(
+ const sound_t sound_id
+) {
+ for (size_t i = 0; SOUND_MAP[i].sound != SOUND_LAST; i++) {
+ if (SOUND_MAP[i].sound == sound_id) {
+ return SOUND_MAP[i].asset_id;
+ }
+ }
+
+ // return failure
+ return ASSET_LAST;
+}
+
void
sound_play(
Mix_Chunk ** const sounds,
- const asset_id_t id
+ const sound_t sound_id
) {
- // check ID
+ // get asset ID
+ const asset_id_t id = get_asset_id(sound_id);
+
+ if (id == ASSET_LAST) {
+ // no sound to play, return
+ return;
+ }
+
+ // check asset ID bounds
if (id <= ASSET_SOUND_FIRST || id >= ASSET_SOUND_LAST) {
- die("invalid sound asset id: %u", id);
+ warn("invalid sound asset id: %u", id);
+ return;
}
// play sound