This commit is contained in:
stiffly
2016-02-01 17:03:41 +01:00
parent c5462b0363
commit 4ccda5ee43
2 changed files with 54 additions and 0 deletions
+11
View File
@@ -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<SoundSystem, Events::Captured> m_ECaptured;
bool OnCaptured(const Events::Captured &e);
EventRelay<SoundSystem, Events::PlayerDamage> m_EPlayerDamage;
bool OnPlayerDamage(const Events::PlayerDamage &e);
EventRelay<SoundSystem, Events::PlayerDeath> m_EPlayerDeath;
bool OnPlayerDeath(const Events::PlayerDeath &e);
EventRelay<SoundSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e);
};
+43
View File
@@ -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.