Drumloop will now play when a team is about to win

This commit is contained in:
stiffly
2016-02-26 16:44:08 +01:00
parent 7dbb9e452b
commit 67dffafe5a
4 changed files with 57 additions and 20 deletions
+1 -1
Submodule assets updated: 00329bcf3e...cea183a06a
+3
View File
@@ -89,7 +89,10 @@ private:
Source* createSource(std::string filePath);
std::unordered_map<EntityID, Source*> m_Sources;
void mainMenuLoop();
void matchBGMLoop();
Source* m_CurrentBGM;
Source* m_CurrentBGMCombo;
bool m_TempPleaseDeleteMeASAP = false;
// Logic
World* m_World = nullptr;
+41 -7
View File
@@ -66,7 +66,9 @@ void SoundManager::Update(double dt)
deleteInactiveEmitters();
updateEmitters(dt);
updateListener(dt);
if(false)
if (m_TempPleaseDeleteMeASAP)
matchBGMLoop();
if (false)
mainMenuLoop();
}
@@ -187,6 +189,30 @@ void SoundManager::mainMenuLoop()
}
}
void SoundManager::matchBGMLoop()
{
if (m_CurrentBGMCombo == nullptr)
return;
auto cCapturePoints = m_World->GetComponents("CapturePoint");
for (auto it = cCapturePoints->begin(); it != cCapturePoints->end(); it++) {
float timeCaptured = (float)(double)(*it)["CaptureTimer"];
float maxTimer = (float)(double)(*it)["CapturePointMaxTimer"];
int capturePointIndex = (int)(*it)["CapturePointNumber"];
if (capturePointIndex == 0) { // Home for red team
if (timeCaptured < 0 && glm::abs(timeCaptured) < maxTimer) {
float gain = glm::abs(timeCaptured) / maxTimer;
setGain(m_CurrentBGMCombo, gain);
}
} else if (capturePointIndex == 4) { // Home for blue team
if (timeCaptured > 0 && timeCaptured < maxTimer) {
float gain = timeCaptured / maxTimer;
setGain(m_CurrentBGMCombo, gain);
}
}
}
}
void SoundManager::playSound(Source* source)
{
alSourcei(source->ALsource, AL_BUFFER, source->SoundResource->Buffer());
@@ -260,7 +286,7 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
auto listenerComponents = m_World->GetComponents("Listener");
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
if ((*it).EntityID != m_LocalPlayer.ID) {
break;
continue;;
}
auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
@@ -348,6 +374,15 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
{
if (e.PlayerID == -1) { // Local player
m_LocalPlayer = e.Player;
if (m_TempPleaseDeleteMeASAP) {
return true;
}
m_CurrentBGMCombo = createSource("Audio/bgm/nearWin.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
m_TempPleaseDeleteMeASAP = true;
return true;
}
return false;
@@ -368,7 +403,6 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
return true;
}
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
{
if (m_CurrentBGM == nullptr) {
@@ -396,10 +430,10 @@ void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundCom
{
float gain;
switch (source->Type) {
case SoundType::SFX: gain = m_SFXVolumeChannel; break;
case SoundType::BGM: gain = m_BGMVolumeChannel; break;
case SoundType::Announcer: gain = m_AnnouncerVolumeChannel; break;
default: gain = 1.f; break;
case SoundType::SFX: gain = m_SFXVolumeChannel; break;
case SoundType::BGM: gain = m_BGMVolumeChannel; break;
case SoundType::Announcer: gain = m_AnnouncerVolumeChannel; break;
default: gain = 1.f; break;
}
alSourcef(source->ALsource, AL_GAIN, (float)(double)(*soundComponent)["Gain"] * gain);
alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]);
+12 -12
View File
@@ -139,18 +139,18 @@ bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
bool SoundSystem::OnTriggerTouch(const Events::TriggerTouch & e)
{
// Temp for play test.
if (m_DrumsIsPlaying) {
return false;
}
if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) {
Events::PlaySoundOnEntity ev; // should be BGM
ev.EmitterID = LocalPlayer.ID;
ev.FilePath = "Audio/bgm/drumstest.wav";
m_EventBroker->Publish(ev);
// Temp for play test.
m_DrumsIsPlaying = true;
}
//// Temp for play test.
//if (m_DrumsIsPlaying) {
// return false;
//}
//if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) {
// Events::PlaySoundOnEntity ev; // should be BGM
// ev.EmitterID = LocalPlayer.ID;
// ev.FilePath = "Audio/bgm/drumstest.wav";
// m_EventBroker->Publish(ev);
// // Temp for play test.
// m_DrumsIsPlaying = true;
//}
return false;
}