aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-01-21 08:51:45 -0500
committerPaul Duncan <pabs@pablotron.org>2019-01-21 08:51:45 -0500
commit4588b0ef57fb3fd8689cd1d241be9b00307baa1f (patch)
tree7039c476b81f42f5ee3205e6e10ff4e22b15569c /src
parent131a454b62687224a2e0a98c05a456729cc00761 (diff)
downloadsok-4588b0ef57fb3fd8689cd1d241be9b00307baa1f.tar.bz2
sok-4588b0ef57fb3fd8689cd1d241be9b00307baa1f.zip
add missing sound events, clean up sound emission
Diffstat (limited to 'src')
-rw-r--r--src/sdl/main.c49
-rw-r--r--src/sdl/sounds.c23
-rw-r--r--src/sdl/sounds.h7
3 files changed, 52 insertions, 27 deletions
diff --git a/src/sdl/main.c b/src/sdl/main.c
index 244d5ab..83ea51e 100644
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
@@ -171,11 +171,9 @@ solve_on_done(
static void
bump(
draw_ctx_t * const draw_ctx,
- Mix_Chunk ** sounds,
const Uint32 ticks
) {
draw_ctx->bump_ticks = ticks;
- sound_play(sounds, SOUND_BUMP);
}
int main(int argc, char *argv[]) {
@@ -228,6 +226,10 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
+ // load sounds
+ Mix_Chunk *sounds[ASSET_SOUND_LAST];
+ sounds_init(sounds);
+
// create window
SDL_Window *win = SDL_CreateWindow(
WINDOW_TITLE,
@@ -243,10 +245,6 @@ int main(int argc, char *argv[]) {
die("SDL_CreateWindow(): %s", SDL_GetError());
}
- // load sounds
- Mix_Chunk *sounds[ASSET_SOUND_LAST];
- sounds_init(sounds);
-
// create renderer
SDL_Renderer *renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer) {
@@ -306,23 +304,25 @@ int main(int argc, char *argv[]) {
break;
case ACTION_MOVE:
if (sok_ctx_move(&ctx, (sok_dir_t) action.data)) {
- if (sok_ctx_is_done(&ctx)) {
- // play sound
- sound_play(sounds, SOUND_LEVEL_DONE);
- }
+ // move success
+ const bool is_done = sok_ctx_is_done(&ctx);
+ sound_play(sounds, is_done ? SOUND_LEVEL_DONE : SOUND_MOVE);
} else {
// move failed
- bump(&draw_ctx, sounds, ticks);
+ sound_play(sounds, SOUND_MOVE_FAILED);
+ bump(&draw_ctx, ticks);
warn("move %s failed", SOK_DIR_TO_STR((sok_dir_t) action.data));
}
break;
case ACTION_UNDO:
if (sok_ctx_undo(&ctx)) {
- // play sound
+ // undo success
sound_play(sounds, SOUND_UNDO);
} else {
- bump(&draw_ctx, sounds, ticks);
+ // undo failed
+ sound_play(sounds, SOUND_UNDO_FAILED);
+ bump(&draw_ctx, ticks);
warn("undo failed");
}
@@ -338,7 +338,9 @@ int main(int argc, char *argv[]) {
// set level
set_level(&draw_ctx, &ctx, level_num);
} else {
- bump(&draw_ctx, sounds, ticks);
+ // next failed
+ sound_play(sounds, SOUND_LEVEL_NEXT_FAILED);
+ bump(&draw_ctx, ticks);
warn("cannot advance to next level");
}
@@ -375,6 +377,10 @@ int main(int argc, char *argv[]) {
break;
case ACTION_SOLVE:
+ // play sound
+ sound_play(sounds, SOUND_SOLVE_START);
+
+ // queue solve
draw_ctx.state = GAME_STATE_SOLVE;
draw_ctx.solve_num_steps = 0;
draw_ctx.solve = solve(&ctx, solve_event_type);
@@ -410,8 +416,11 @@ int main(int argc, char *argv[]) {
break;
case ACTION_SOLVE_CANCEL:
- SDL_Log("solve cancelled by user");
+ // play sound
sound_play(sounds, SOUND_SOLVE_CANCEL);
+
+ // cancel solve
+ SDL_Log("solve cancelled by user");
draw_ctx.state = GAME_STATE_PLAY;
solve_cancel(draw_ctx.solve);
@@ -421,15 +430,21 @@ int main(int argc, char *argv[]) {
break;
case ACTION_SOLVE_EVENT_DONE:
- SDL_Log("solve done");
+ // play sound
sound_play(sounds, SOUND_SOLVE_DONE);
+
+ // handle solve done
+ SDL_Log("solve done");
draw_ctx.state = GAME_STATE_PLAY;
- // TODO: handle success
solve_fini(draw_ctx.solve, solve_on_done, &ctx);
draw_ctx.solve = NULL;
break;
case ACTION_SOLVE_EVENT_FAIL:
+ // play sound
+ sound_play(sounds, SOUND_SOLVE_FAILED);
+
+ // handle solve fail
SDL_Log("solve fail");
draw_ctx.state = GAME_STATE_PLAY;
solve_fini(draw_ctx.solve, NULL, NULL);
diff --git a/src/sdl/sounds.c b/src/sdl/sounds.c
index 2c8c3f1..a78e8ad 100644
--- a/src/sdl/sounds.c
+++ b/src/sdl/sounds.c
@@ -9,15 +9,20 @@ 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 },
+ { SOUND_MOVE, ASSET_LAST }, // none
+ { SOUND_MOVE_FAILED, ASSET_SOUND_HIT_1_WAV }, // bump
+ { SOUND_LEVEL_DONE, ASSET_SOUND_POWERUP_3_WAV },
+ { SOUND_UNDO, ASSET_SOUND_HIT_1_WAV }, // bump
+ { SOUND_UNDO_FAILED, ASSET_SOUND_HIT_1_WAV }, // bump
+ { SOUND_LEVEL_NEXT, ASSET_SOUND_POWERUP_1_WAV },
+ { SOUND_LEVEL_NEXT_FAILED, ASSET_SOUND_HIT_1_WAV }, // bump
+ { SOUND_LEVEL_RESET, ASSET_SOUND_UNDO_0_WAV },
+ { SOUND_LEVEL_WARP, ASSET_SOUND_POWERUP_1_WAV },
+ { SOUND_SOLVE_START, ASSET_LAST }, // none
+ { SOUND_SOLVE_FAILED, ASSET_LAST }, // none
+ { SOUND_SOLVE_CANCEL, ASSET_SOUND_HIT_2_WAV },
+ { SOUND_SOLVE_DONE, ASSET_SOUND_POWERUP_4_WAV },
+ { SOUND_LAST, ASSET_LAST },
};
void
diff --git a/src/sdl/sounds.h b/src/sdl/sounds.h
index 38d6a14..d2bd023 100644
--- a/src/sdl/sounds.h
+++ b/src/sdl/sounds.h
@@ -5,14 +5,19 @@
#include "assets.h"
typedef enum {
- SOUND_BUMP,
+ SOUND_MOVE,
+ SOUND_MOVE_FAILED,
SOUND_LEVEL_DONE,
SOUND_UNDO,
+ SOUND_UNDO_FAILED,
SOUND_LEVEL_NEXT,
+ SOUND_LEVEL_NEXT_FAILED,
SOUND_LEVEL_RESET,
SOUND_LEVEL_WARP,
+ SOUND_SOLVE_START,
SOUND_SOLVE_CANCEL,
SOUND_SOLVE_DONE,
+ SOUND_SOLVE_FAILED,
SOUND_LAST,
} sound_t;