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:
@@ -133,8 +133,6 @@ private:
|
||||
bool OnShoot(const Events::Shoot &e);
|
||||
EventRelay<SoundManager, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||
EventRelay<SoundManager, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand &e);
|
||||
EventRelay<SoundManager, Events::Captured> m_ECaptured;
|
||||
bool OnCaptured(const Events::Captured &e);
|
||||
EventRelay<SoundManager, Events::PlayerDamage> m_EPlayerDamage;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../Engine/Core/System.h"
|
||||
#include "../Engine/Sound/SoundManager.h"
|
||||
#include "../Engine/Core/EPlayerSpawned.h"
|
||||
#include "../Engine/Input/EInputCommand.h"
|
||||
|
||||
|
||||
class SoundSystem : public PureSystem, ImpureSystem, SoundManager
|
||||
@@ -19,14 +20,19 @@ private:
|
||||
World* m_World = nullptr;
|
||||
EventBroker* m_EventBroker = nullptr;
|
||||
|
||||
void playerJumps();
|
||||
|
||||
|
||||
// TODO: WIP Update this
|
||||
double m_DistanceMoved = 0.0;
|
||||
const float m_PlayerStepLength = 1.0;
|
||||
float m_DistanceMoved = 0.0f;
|
||||
const float m_PlayerStepLength = 2.0f;
|
||||
glm::vec3 m_LastPosition = glm::vec3();
|
||||
bool m_LeftFoot = false;
|
||||
|
||||
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||
EventRelay<SoundSystem, Events::InputCommand> m_InputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand &e);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,6 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker, bool editorMo
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundManager::OnShoot);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundManager::OnPlayerDamage);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SoundManager::OnInputCommand);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundManager::OnCaptured);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundManager::OnTriggerTouch);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SoundManager::OnPause);
|
||||
@@ -182,16 +181,7 @@ void SoundManager::stopSound(Source* source)
|
||||
alSourceStop(source->ALsource);
|
||||
}
|
||||
|
||||
void SoundManager::playerJumps()
|
||||
{
|
||||
glm::vec3 vel = (glm::vec3)m_World->GetComponent(m_LocalPlayer.ID, "Physics")["Velocity"];
|
||||
if (vel.y == 0) {
|
||||
Source* source = createSource("Audio/jump/jump1.wav");
|
||||
source->Type = SoundType::SFX;
|
||||
m_Sources[createChildEmitter(m_LocalPlayer)] = source;
|
||||
playSound(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SoundManager::playerStep(double dt)
|
||||
{
|
||||
@@ -303,26 +293,6 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned & e)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnInputCommand(const Events::InputCommand & e)
|
||||
{
|
||||
if (e.Command == "Jump" && e.Value > 0) {
|
||||
if (e.PlayerID == -1) { // local player
|
||||
playerJumps();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// TEMP: testing purpose (obviously)
|
||||
if (e.Command == "TakeDamage" && e.Value > 0) {
|
||||
if (e.PlayerID == -1) { //Local Player
|
||||
Events::PlayerDamage ePlayerDamage;
|
||||
ePlayerDamage.Damage = 1;
|
||||
ePlayerDamage.Player = EntityWrapper(m_World, e.Player.ID);
|
||||
m_EventBroker->Publish(ePlayerDamage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SoundManager::OnCaptured(const Events::Captured & e)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user