Player walk is now based on distance traveled, and it is also reset when key is released. However when dashing the player step sound is still played. The distance of a step is also hard coded in the header file. Will config it up some day.

This commit is contained in:
stiffly
2016-02-05 17:46:27 +01:00
parent 454eef8225
commit becb197feb
4 changed files with 60 additions and 56 deletions
+51 -21
View File
@@ -9,11 +9,12 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
m_World = world;
m_EventBroker = eventbroker;
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand);
}
void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt)
{
}
void SoundSystem::Update(double dt)
@@ -24,26 +25,25 @@ void SoundSystem::Update(double dt)
void SoundSystem::playerStep(double dt)
{
//if (!m_LocalPlayer.Valid()) {
// return;
//}
//glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"];
//glm::vec3 vel = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["Velocity"];
//glm::vec3 difference = pos - m_LastPosition;
//m_DistanceMoved += glm::length(difference);
//bool isAirborne = vel.y != 0;
//if (m_DistanceMoved > m_PlayerStepLength && !isAirborne) {
// // Player is walking
// if (m_TimeSinceLastFootstep * std::min<float>(playerSpeed, 2) > m_PlayerFootstepInterval) {
// // Create footstep sound
// Events::PlaySoundOnEntity e;
// e.EmitterID = createChildEmitter(m_LocalPlayer);
// e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav";
// m_LeftFoot = !m_LeftFoot;
// m_EventBroker->Publish(e);
// m_TimeSinceLastFootstep = 0;
// }
//}
if (!m_LocalPlayer.Valid()) {
return;
}
glm::vec3 pos = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Transform")["Position"];
glm::vec3 vel = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["Velocity"];
glm::vec3 difference = pos - m_LastPosition;
m_LastPosition = pos;
m_DistanceMoved += glm::length(difference);
bool isAirborne = vel.y != 0;
if (m_DistanceMoved > m_PlayerStepLength && !isAirborne) {
// Player moved a step's distance
// Create footstep sound
Events::PlaySoundOnEntity e;
e.EmitterID = createChildEmitter(m_LocalPlayer);
e.FilePath = m_LeftFoot ? "Audio/footstep/footstep2.wav" : "Audio/footstep/footstep3.wav";
m_LeftFoot = !m_LeftFoot;
m_EventBroker->Publish(e);
m_DistanceMoved = 0.f;
}
}
bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
@@ -64,3 +64,33 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
}
return true;
}
bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
{
if (e.Command == "Jump" && e.Value > 0) {
if (e.PlayerID == -1) { // local player
playerJumps();
return true;
}
}
if (e.Command == "Forward" || e.Command == "Right") {
if (e.Value == 0) {
// Key released
// Reset the distance moved
m_DistanceMoved = 0.f;
}
}
return false;
}
void SoundSystem::playerJumps()
{
glm::vec3 vel = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["Velocity"];
if (vel.y == 0) {
Events::PlaySoundOnEntity e;
e.EmitterID = createChildEmitter(m_LocalPlayer);
e.FilePath = "Audio/jump/jump1.wav";
m_EventBroker->Publish(e);
}
}