From a5105e5859f15588e269bc5d14f6450b5e90fe29 Mon Sep 17 00:00:00 2001 From: Stiffly Date: Tue, 3 Jun 2014 19:44:33 +0200 Subject: [PATCH] tank modifications --- src/Components/SoundEmitter.h | 3 ++- src/GameWorld.cpp | 6 ++++++ src/Systems/TankSteeringSystem.cpp | 12 ++++++++++++ src/Systems/TankSteeringSystem.h | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Components/SoundEmitter.h b/src/Components/SoundEmitter.h index cc9b738..e969fba 100755 --- a/src/Components/SoundEmitter.h +++ b/src/Components/SoundEmitter.h @@ -10,13 +10,14 @@ namespace Components struct SoundEmitter : Component { + enum class SoundType { SOUND_3D, SOUND_2D }; - SoundEmitter() : Gain(1.f), MaxDistance(1.f), MinDistance(1.f), Pitch(1.f), Loop(false) {} + SoundEmitter() : Gain(1.f), MaxDistance(10000.f), MinDistance(1.f), Pitch(1.f), Loop(false) {} float Gain; float MaxDistance; float MinDistance; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 4faebb7..19af11a 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -653,6 +653,7 @@ EntityID GameWorld::CreateTank(int playerID) barrelSteering->ShotSpeed = 70.f; barrelSteering->LowerRotationLimit = glm::radians(-10.f); barrelSteering->UpperRotationLimit = glm::radians(40.f); + { auto shot = CreateEntity(barrel); auto transform = AddComponent(shot); @@ -660,6 +661,11 @@ EntityID GameWorld::CreateTank(int playerID) transform->Orientation = glm::angleAxis(-glm::pi() / 2.f, glm::vec3(1, 0, 0)); transform->Scale = glm::vec3(3.f); AddComponent(shot); + auto soundEmitter = AddComponent(shot); + soundEmitter->MinDistance = 1000; + soundEmitter->Gain = 1; + soundEmitter->Loop = false; + auto physics = AddComponent(shot); physics->Mass = 25.f; physics->Static = false; diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index a04dbc8..41f17c9 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -108,6 +108,18 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit m_TimeSinceLastShot[tankSteeringComponent->Barrel] += dt; } + + auto shot = m_World->GetComponent(entity); + if(shot) + { + if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5) + { + Events::PlaySFX e; + e.Resource = "Sounds/SFX/LongBoom.wav"; + e.Emitter = entity; + EventBroker->Publish(e); + } + } } bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e ) diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 8c996fa..a4ed5a9 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -29,6 +29,8 @@ #include "Components/TriggerExplosion.h" #include "Components/FrameTimer.h" +#include "Events/PlaySFX.h" + #include "Events/Damage.h" #include "Components/Vehicle.h" #include "Components/Player.h"