Added some sound and music toggles

This commit is contained in:
Linus_Probert 2018-02-20 10:45:54 +01:00
parent 0adcbc1b11
commit 548eecf3c0
4 changed files with 51 additions and 3 deletions

View File

@ -348,6 +348,22 @@ handle_main_events(SDL_Event *event)
toggleInGameMenu(NULL); toggleInGameMenu(NULL);
return true; return true;
} }
if (keyboard_mod_press(SDLK_m, KMOD_CTRL, event)) {
if (mixer_toggle_music())
gui_log("Music enabled");
else
gui_log("Music disabled");
return true;
}
if (keyboard_mod_press(SDLK_s, KMOD_CTRL, event)) {
if (mixer_toggle_sound())
gui_log("Sound enabled");
else
gui_log("Sound disabled");
return true;
}
} }
return false; return false;
} }

View File

@ -23,6 +23,9 @@
static Mix_Music *music[LAST_MUSIC]; static Mix_Music *music[LAST_MUSIC];
static Mix_Chunk *effects[LAST_EFFECT]; static Mix_Chunk *effects[LAST_EFFECT];
static bool sound_enabled = true;
static bool music_enabled = true;
static Mix_Music* static Mix_Music*
load_song(char *path) load_song(char *path)
{ {
@ -85,9 +88,32 @@ mixer_init(void)
load_music(); load_music();
} }
bool
mixer_toggle_sound(void)
{
sound_enabled = !sound_enabled;
return sound_enabled;
}
bool
mixer_toggle_music(void)
{
music_enabled = !music_enabled;
if (Mix_PlayingMusic() && !music_enabled)
Mix_PauseMusic();
else if (Mix_PausedMusic())
Mix_ResumeMusic();
return music_enabled;
}
void void
mixer_play_effect(Fx fx) mixer_play_effect(Fx fx)
{ {
if (!sound_enabled)
return;
if (Mix_PlayChannel( -1, effects[fx], 0) == -1) if (Mix_PlayChannel( -1, effects[fx], 0) == -1)
error("Unable to play sound: %u", (unsigned int) fx); error("Unable to play sound: %u", (unsigned int) fx);
} }
@ -95,6 +121,9 @@ mixer_play_effect(Fx fx)
void void
mixer_play_music(Music mus) mixer_play_music(Music mus)
{ {
if (!music_enabled)
return;
if (Mix_PlayingMusic()) if (Mix_PlayingMusic())
mixer_stop_music(); mixer_stop_music();

View File

@ -55,6 +55,12 @@ typedef enum Fx_t {
void void
mixer_init(void); mixer_init(void);
bool
mixer_toggle_sound(void);
bool
mixer_toggle_music(void);
void void
mixer_play_effect(Fx fx); mixer_play_effect(Fx fx);

View File

@ -372,9 +372,6 @@ player_print(Player *p)
debug("\n"); debug("\n");
debug("--------=== <[ Player Stats ]> ===--------"); debug("--------=== <[ Player Stats ]> ===--------");
debug("HP: %d", p->stats.hp);
debug("Level: %u\tXP:\t%u", p->stats.lvl, p->xp);
debug("Gold: %.2f", p->gold);
debug("Hits: %u\tMisses:\t%u", p->hits, p->misses); debug("Hits: %u\tMisses:\t%u", p->hits, p->misses);
debug("Kills: %u", p->kills); debug("Kills: %u", p->kills);
debug("Steps: %u", p->total_steps); debug("Steps: %u", p->total_steps);