Add a key to toggle the music off, fix little guy's movement speed
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
|
||||
#include <sdl3game/assets.h>
|
||||
#include <sdl3game/error.h>
|
||||
#include <sdl3game/iterator.h>
|
||||
#include <sdl3game/tilemap.h>
|
||||
#include <sdl3game/heap.h>
|
||||
@@ -30,6 +31,29 @@ char *spritepaths[] = {
|
||||
|
||||
char dirnamebuf[1024];
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *music_toggle(actor *obj, SDL_Event *event)
|
||||
{
|
||||
SDL_PropertiesID bgmprops = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
if ( MIX_TrackPlaying(game.tracks[GAME_AUDIO_TRACK_BGM]) ) {
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
MIX_StopTrack(game.tracks[GAME_AUDIO_TRACK_BGM], 0),
|
||||
AKERR_SDL,
|
||||
"%s",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
SDL_SetNumberProperty(bgmprops, MIX_PROP_PLAY_LOOPS_NUMBER, -1);
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
MIX_PlayTrack(game.tracks[GAME_AUDIO_TRACK_BGM], bgmprops),
|
||||
AKERR_SDL,
|
||||
"%s",
|
||||
SDL_GetError());
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *user_breakpoint(actor *obj, SDL_Event *event)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -111,12 +135,16 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
controlmap->controls[3].event_off = SDL_EVENT_KEY_UP;
|
||||
controlmap->controls[3].handler_on = &SDL3GActor_cmhf_right_on;
|
||||
controlmap->controls[3].handler_off = &SDL3GActor_cmhf_right_off;
|
||||
|
||||
|
||||
// Breakpoint
|
||||
controlmap->controls[4].key = SDLK_ESCAPE;
|
||||
controlmap->controls[4].event_on = SDL_EVENT_KEY_DOWN;
|
||||
controlmap->controls[4].handler_on = &user_breakpoint;
|
||||
|
||||
// Toggle the music
|
||||
controlmap->controls[5].key = SDLK_M;
|
||||
controlmap->controls[5].event_on = SDL_EVENT_KEY_DOWN;
|
||||
controlmap->controls[5].handler_on = &music_toggle;
|
||||
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
|
||||
Reference in New Issue
Block a user