diff --git a/res/sounds/chime.wav b/res/sounds/chime.wav new file mode 100644 index 00000000..99741bc8 Binary files /dev/null and b/res/sounds/chime.wav differ diff --git a/res/sounds/walking-sound.wav b/res/sounds/walking-sound.wav new file mode 100644 index 00000000..9533336d Binary files /dev/null and b/res/sounds/walking-sound.wav differ diff --git a/src/gui_controller/game/states/cell_movement.h b/src/gui_controller/game/states/cell_movement.h index 33fd71df..76c7bf7f 100644 --- a/src/gui_controller/game/states/cell_movement.h +++ b/src/gui_controller/game/states/cell_movement.h @@ -5,6 +5,7 @@ #include "gui_controller/timed_count.h" #include "gui_controller/utils.h" #include "static_data/game_config.h" +#include "sound_manager/sound_manager.h" #include #include #include @@ -75,6 +76,7 @@ class CellMovement : public GameState { d->setNextCell(d->getPrevOnPath().lock()); gm->changeState(GUIGameState::kMoveTransition); } + sound::playSound("walking-sound", 80); return; } @@ -87,6 +89,7 @@ class CellMovement : public GameState { } else if (clicked_left && !neighbours[3].expired()) { r_selected = 3; } else if (clicked_enter) { + sound::playSound("chime"); d->setNextCell(d->getNextOnPath().lock()); gm->changeState(GUIGameState::kMoveTransition); } diff --git a/src/sound_manager/sound_manager.h b/src/sound_manager/sound_manager.h new file mode 100644 index 00000000..c28b9c95 --- /dev/null +++ b/src/sound_manager/sound_manager.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include + +namespace sound { +class SoundManager { +public: + static SoundManager &getInstance() { + static SoundManager instance; + return instance; + } + void playSound(const std::string& sound_name, const float volume) { + sound_buffer = std::make_unique(); + sound = std::make_unique(); + if (sound_buffer->loadFromFile(cfg::SOUNDS_PATH + sound_name + ".wav")) { + sound->setBuffer(*sound_buffer); + sound->setVolume(volume); + sound->play(); + } + } +private: + SoundManager() = default; + + std::unique_ptr sound_buffer; + std::unique_ptr sound; +}; + +static void playSound(const std::string& sound_name, float volume = 100.f) { + sound::SoundManager::getInstance().playSound(sound_name, volume); +} +} diff --git a/src/static_data/game_config.h b/src/static_data/game_config.h index 45f7bf5a..2bf42760 100644 --- a/src/static_data/game_config.h +++ b/src/static_data/game_config.h @@ -11,6 +11,7 @@ const unsigned CELL_SIZE = 20; const std::string WINDOW_NAME = "*EPIC DUNGEONS*"; const std::string FONTS_PATH = "res/fonts/"; const std::string SPRITES_PATH = "res/sprites/"; +const std::string SOUNDS_PATH = "res/sounds/"; const keyboard::Key CONTROLS_MOVE_RIGHT = keyboard::Key::KEY_RIGHT; const keyboard::Key CONTROLS_MOVE_DOWN = keyboard::Key::KEY_DOWN;