diff --git a/src/main.c b/src/main.c index 2968d55..786da9f 100644 --- a/src/main.c +++ b/src/main.c @@ -348,6 +348,22 @@ handle_main_events(SDL_Event *event) toggleInGameMenu(NULL); 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; } diff --git a/src/mixer.c b/src/mixer.c index c7f0652..8abbe93 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -23,6 +23,9 @@ static Mix_Music *music[LAST_MUSIC]; static Mix_Chunk *effects[LAST_EFFECT]; +static bool sound_enabled = true; +static bool music_enabled = true; + static Mix_Music* load_song(char *path) { @@ -85,9 +88,32 @@ mixer_init(void) 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 mixer_play_effect(Fx fx) { + if (!sound_enabled) + return; + if (Mix_PlayChannel( -1, effects[fx], 0) == -1) error("Unable to play sound: %u", (unsigned int) fx); } @@ -95,6 +121,9 @@ mixer_play_effect(Fx fx) void mixer_play_music(Music mus) { + if (!music_enabled) + return; + if (Mix_PlayingMusic()) mixer_stop_music(); diff --git a/src/mixer.h b/src/mixer.h index 799b627..1dd42f7 100644 --- a/src/mixer.h +++ b/src/mixer.h @@ -55,6 +55,12 @@ typedef enum Fx_t { void mixer_init(void); +bool +mixer_toggle_sound(void); + +bool +mixer_toggle_music(void); + void mixer_play_effect(Fx fx); diff --git a/src/player.c b/src/player.c index 8d18350..7673f35 100644 --- a/src/player.c +++ b/src/player.c @@ -372,9 +372,6 @@ player_print(Player *p) debug("\n"); 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("Kills: %u", p->kills); debug("Steps: %u", p->total_steps);