diff --git a/include/Engine/Sound/SoundSystem.h b/include/Engine/Sound/SoundSystem.h index 5d57d5b6..4ceed60f 100644 --- a/include/Engine/Sound/SoundSystem.h +++ b/include/Engine/Sound/SoundSystem.h @@ -24,6 +24,9 @@ #include "Core/EPlayerSpawned.h" #include "Input/EInputCommand.h" #include "Core/ECaptured.h" +#include "Core/EPlayerDamage.h" +#include "Core/EPlayerDeath.h" +#include "Core/EPlayerHealthPickup.h" enum class SoundType { SFX, @@ -120,6 +123,14 @@ private: bool OnInputCommand(const Events::InputCommand &e); EventRelay m_ECaptured; bool OnCaptured(const Events::Captured &e); + EventRelay m_EPlayerDamage; + bool OnPlayerDamage(const Events::PlayerDamage &e); + EventRelay m_EPlayerDeath; + bool OnPlayerDeath(const Events::PlayerDeath &e); + EventRelay m_EPlayerHealthPickup; + bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e); + + }; diff --git a/src/Engine/Sound/SoundSystem.cpp b/src/Engine/Sound/SoundSystem.cpp index dbabb32d..b4de9d31 100644 --- a/src/Engine/Sound/SoundSystem.cpp +++ b/src/Engine/Sound/SoundSystem.cpp @@ -122,6 +122,7 @@ void SoundSystem::updateEmitters(double dt) setSourceVel(it->second->ALsource, velocity); float gain; (bool)(it->second->Type) ? gain = m_SFXVolumeChannel : gain = m_BGMVolumeChannel; + auto emitter = m_World->GetComponent(it->first, "SoundEmitter"); setSoundProperties(it->second->ALsource, &emitter); @@ -372,6 +373,48 @@ bool SoundSystem::OnCaptured(const Events::Captured & e) return false; } +bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e) +{ + if (e.Player.ID == m_LocalPlayer) { + Events::PlaySoundOnEntity ev; + EntityID child = m_World->CreateEntity(m_LocalPlayer); + m_World->AttachComponent(child, "Transform"); + m_World->AttachComponent(child, "SoundEmitter"); + ev.EmitterID = child; + ev.FilePath = "Audio/hurt/hurt3.wav"; // random between a bunch + m_EventBroker->Publish(ev); + } + return false; +} + +bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e) +{ + if (e.PlayerID == m_LocalPlayer) { + Events::PlaySoundOnEntity ev; + EntityID child = m_World->CreateEntity(m_LocalPlayer); + m_World->AttachComponent(child, "Transform"); + m_World->AttachComponent(child, "SoundEmitter"); + ev.EmitterID = child; + ev.FilePath = "Audio/die/die2.wav"; // random between a bunch + m_EventBroker->Publish(ev); + } + return false; +} + +bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e) +{ + if (e.PlayerHealedID == m_LocalPlayer) { + Events::PlaySoundOnEntity ev; + EntityID child = m_World->CreateEntity(m_LocalPlayer); + m_World->AttachComponent(child, "Transform"); + m_World->AttachComponent(child, "SoundEmitter"); + ev.EmitterID = child; + ev.FilePath = "Audio/pickup/pickup2.wav"; + m_EventBroker->Publish(ev); + } + return false; +} + void SoundSystem::setListenerOri(glm::vec3 ori) { // Calculate forward and up vector.