diff --git a/assets/sounds/jump.wav b/assets/sounds/jump.wav new file mode 100644 index 00000000..642ae89a Binary files /dev/null and b/assets/sounds/jump.wav differ diff --git a/sources/Component/Sound/SoundComponent.cpp b/sources/Component/Sound/SoundComponent.cpp index 46e15b8d..176230f8 100644 --- a/sources/Component/Sound/SoundComponent.cpp +++ b/sources/Component/Sound/SoundComponent.cpp @@ -3,6 +3,7 @@ // #include +#include #include "SoundComponent.hpp" namespace BBM @@ -10,18 +11,18 @@ namespace BBM SoundComponent::SoundComponent(WAL::Entity &entity, \ std::map &soundPath) : WAL::Component(entity), - _soundIndex(IDLE) + _soundIndex(IDLE), + _soundPath(soundPath) { - for (int i = 0; i < DEATH + 1; i++) { + for (int i = 0; i <= DEATH; i++) + this->_isLoad[static_cast(i)] = false; + /*for (int i = 0; i <= DEATH; i++) { if (soundPath.at(static_cast(i)).empty()) { this->_isLoad[static_cast(i)] = false; } else { this->_isLoad[static_cast(i)] = true; this->_soundList[static_cast(i)] = RAY::Audio::Sound(soundPath.at(static_cast(i))); } - } - /*for (int i = 0; i < DEATH + 1; i++) { - std::cout << i << this->_isLoad.at(static_cast(i)) << soundPath.at(static_cast(i)) << std::endl; }*/ } @@ -36,22 +37,19 @@ std::map &soundPath) return new SoundComponent(entity); } - void SoundComponent::loadSound(void) + void SoundComponent::playSound(void) { - std::cout << this->_soundIndex << std::endl; if (!this->_isLoad.at(this->_soundIndex)) - return; - if (!this->_soundList[this->_soundIndex].isPlaying()) { - std::cout << this->_soundIndex << std::endl; + this->_soundList[this->_soundIndex] = RAY::Audio::Sound(this->_soundPath.at(this->_soundIndex)); + if (!this->_soundList[this->_soundIndex].isPlaying()) this->_soundList[this->_soundIndex].play(); - } } - void SoundComponent::unloadSound(void) + void SoundComponent::stopSound(void) { if (!this->_isLoad.at(this->_soundIndex)) return; - if (!this->_soundList[this->_soundIndex].isPlaying()) + if (this->_soundList[this->_soundIndex].isPlaying()) this->_soundList[this->_soundIndex].stop(); } diff --git a/sources/Component/Sound/SoundComponent.hpp b/sources/Component/Sound/SoundComponent.hpp index 1feaa261..df2d3925 100644 --- a/sources/Component/Sound/SoundComponent.hpp +++ b/sources/Component/Sound/SoundComponent.hpp @@ -30,10 +30,10 @@ namespace BBM soundIndex getIndex(); //! @brief load Sound - void loadSound(); + void playSound(); //! @brief unload Sound - void unloadSound(); + void stopSound(); //! @brief put Sound on hold void pauseSound(); @@ -47,11 +47,10 @@ namespace BBM //! @brief is Sound playing bool isPlaying(void); - //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; //! @brief Create a new SoundComponent at a certain Sound - SoundComponent(WAL::Entity &entity, std::map &SoundPath); + SoundComponent(WAL::Entity &entity, std::map &); //! @brief A Sound component is copy constructable SoundComponent(const SoundComponent &) = default; //! @brief A default destructor @@ -63,8 +62,13 @@ namespace BBM std::map _soundList; std::map _isLoad; + + std::map _soundPath; + //! SoundIndex soundIndex _soundIndex; + + //! @brief Create a new SoundComponent linked to a specific entity explicit SoundComponent(WAL::Entity &entity); diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 7030294f..d556b3b7 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -31,6 +31,7 @@ #include "Map/Map.hpp" #include "Component/Music/MusicComponent.hpp" #include "Component/Sound/SoundComponent.hpp" +#include "System/Sound/PlayerSoundManagerSystem.hpp" namespace RAY2D = RAY::Drawables::Drawables2D; namespace RAY3D = RAY::Drawables::Drawables3D; @@ -53,12 +54,13 @@ namespace BBM .addSystem() .addSystem() .addSystem(wal) - .addSystem(); + .addSystem() + .addSystem(); } void enableRaylib(WAL::Wal &wal) { - RAY::TraceLog::setLevel(LOG_WARNING); + //RAY::TraceLog::setLevel(LOG_WARNING); RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE); wal.addSystem(wal, window); } @@ -70,7 +72,7 @@ namespace BBM {SoundComponent::IDLE, ""}, {SoundComponent::JUMP, ""}, {SoundComponent::BOMB, ""}, - {SoundComponent::MOVE, "assets/sounds/weird.wav"}, + {SoundComponent::MOVE, "assets/sounds/jump.wav"}, {SoundComponent::HURT, ""}, {SoundComponent::THROW, ""}, {SoundComponent::DEATH, ""} @@ -79,10 +81,12 @@ namespace BBM .addComponent() .addComponent("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() + .addComponent(1) .addComponent() .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 1) .addComponent(2) .addComponent() + //.addComponent("assets/musics/music_win.ogg"); .addComponent(soundPath); scene->addEntity("cube") .addComponent(-5, 0, -5) diff --git a/sources/System/Sound/PlayerSoundManagerSystem.cpp b/sources/System/Sound/PlayerSoundManagerSystem.cpp index 512a5603..187f55e3 100644 --- a/sources/System/Sound/PlayerSoundManagerSystem.cpp +++ b/sources/System/Sound/PlayerSoundManagerSystem.cpp @@ -6,6 +6,14 @@ namespace BBM { + + SoundManagerSystem::SoundManagerSystem() + : WAL::System({ + typeid(SoundComponent), + typeid(HealthComponent) + }) + {} + void SoundManagerSystem::onFixedUpdate(WAL::Entity &entity) { if (!entity.hasComponent()) @@ -15,12 +23,13 @@ namespace BBM { auto &health = entity.getComponent(); sound.setIndex(SoundComponent::BOMB); - controllable.bomb ? sound.loadSound() : sound.unloadSound(); + if (controllable.bomb) + sound.playSound(); sound.setIndex(SoundComponent::JUMP); - controllable.jump ? sound.loadSound() : sound.unloadSound(); + if (controllable.jump) + sound.playSound(); sound.setIndex(SoundComponent::MOVE); - (controllable.move.x != 0 || controllable.move.y != 0) ? sound.loadSound() : sound.unloadSound(); - sound.setIndex(SoundComponent::DEATH); - health.getHealthPoint() == 0 ? sound.loadSound() : sound.unloadSound(); + if (controllable.move.x != 0 || controllable.move.y != 0) + sound.playSound(); } } \ No newline at end of file diff --git a/sources/System/Sound/PlayerSoundManagerSystem.hpp b/sources/System/Sound/PlayerSoundManagerSystem.hpp index aff694c2..38cd4bfa 100644 --- a/sources/System/Sound/PlayerSoundManagerSystem.hpp +++ b/sources/System/Sound/PlayerSoundManagerSystem.hpp @@ -20,7 +20,7 @@ namespace BBM void onFixedUpdate(WAL::Entity &entity) override; //! @brief ctor - SoundManagerSystem(WAL::Wal &wal, RAY::Window &window); + SoundManagerSystem(); //! @brief Default copy ctor SoundManagerSystem(const SoundManagerSystem &) = default; //! @brief Default dtor