From 56e6545f0fc19463c3f837d53882fc72b6116ee2 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Wed, 4 Jun 2014 23:54:52 +0200 Subject: [PATCH] Direct damage and VulnerableToSplash flag on Health component --- src/Components/DamageModel.h | 27 +++++ src/Components/Health.h | 5 +- src/GameWorld.cpp | 17 +-- src/GameWorld.h | 1 + src/Systems/DamageSystem.cpp | 1 + src/Systems/DamageSystem.h | 1 + src/Systems/TankSteeringSystem.cpp | 103 ++++++++++-------- src/Systems/WallSystem.cpp | 13 +++ src/Systems/WallSystem.h | 1 + vs11/Returngeance/Returngeance.vcxproj | 1 + .../Returngeance/Returngeance.vcxproj.filters | 31 ++++-- 11 files changed, 141 insertions(+), 60 deletions(-) create mode 100644 src/Components/DamageModel.h diff --git a/src/Components/DamageModel.h b/src/Components/DamageModel.h new file mode 100644 index 0000000..6e34cf9 --- /dev/null +++ b/src/Components/DamageModel.h @@ -0,0 +1,27 @@ +#ifndef Components_DamageModel_h__ +#define Components_DamageModel_h__ + +#include + +#include "Component.h" + +namespace Components +{ + + struct DamageModel : Component + { + DamageModel() + : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) + , ShadowCaster(true) + , Transparent(false) + { } + std::string ModelFile; + glm::vec4 Color; + bool ShadowCaster; + bool Transparent; + + virtual DamageModel* Clone() const override { return new DamageModel(*this); } + }; + +} +#endif // !Components_DamageModel_h__ \ No newline at end of file diff --git a/src/Components/Health.h b/src/Components/Health.h index ca8daee..c52fae2 100644 --- a/src/Components/Health.h +++ b/src/Components/Health.h @@ -9,9 +9,12 @@ namespace Components struct Health : Component { Health() - : Amount(1.0f) { } + : Amount(1.0f) + , VulnerableToSplash(true) + { } float Amount; + bool VulnerableToSplash; virtual Health* Clone() const override { return new Health(*this); } }; diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index f18ef16..07bab79 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -650,9 +650,12 @@ EntityID GameWorld::CreateWall(EntityID parent, glm::vec3 pos, glm::quat orienta auto model = AddComponent(wall); model->ModelFile = "Models/Wall/WallWhole/Wall.obj"; + auto damageModel = AddComponent(wall); + damageModel->ModelFile = "Models/Wall/WallWhole/WallCracks.obj"; auto health = AddComponent(wall); health->Amount = 50.f; + health->VulnerableToSplash = false; auto shape = CreateEntity(wall); auto shapetransform = AddComponent(shape); @@ -752,7 +755,7 @@ void GameWorld::CreateTerrain() } CreateBase(glm::quat(), 1); - //CreateBase(glm::quat(glm::vec3(0, glm::pi(), 0)), 2); + CreateBase(glm::quat(glm::vec3(0, glm::pi(), 0)), 2); { auto tree = CreateEntity(); @@ -1085,12 +1088,12 @@ void GameWorld::CreateBase(glm::quat orientation, int teamID) CreateGate(base, glm::vec3(273.f, 40.185f, 0.06f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0)), teamID); CreateWall(base, glm::vec3(273.f, 40.3f, -55.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - //CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - //CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - //CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - //CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - //CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); - //CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); + CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0))); CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0)), teamID); } diff --git a/src/GameWorld.h b/src/GameWorld.h index 0b2bcfa..85539ca 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -30,6 +30,7 @@ #include "Components/DirectionalLight.h" #include "Components/Input.h" #include "Components/Model.h" +#include "Components/DamageModel.h" #include "Components/ParticleEmitter.h" #include "Components/Particle.h" #include "Components/PointLight.h" diff --git a/src/Systems/DamageSystem.cpp b/src/Systems/DamageSystem.cpp index 53be57c..ffbce89 100644 --- a/src/Systems/DamageSystem.cpp +++ b/src/Systems/DamageSystem.cpp @@ -4,6 +4,7 @@ void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf ) { cf->Register([]() { return new Components::Health(); }); + cf->Register([]() { return new Components::DamageModel(); }); } void Systems::DamageSystem::Initialize() diff --git a/src/Systems/DamageSystem.h b/src/Systems/DamageSystem.h index a77a600..2b1a43a 100644 --- a/src/Systems/DamageSystem.h +++ b/src/Systems/DamageSystem.h @@ -4,6 +4,7 @@ #include "System.h" #include "Components/Health.h" +#include "Components/DamageModel.h" #include "Events/Damage.h" #include "Events/OnDead.h" diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index f20279a..c9c1022 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -50,7 +50,6 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit eSteering.Handbrake = inputController->Handbrake; EventBroker->Publish(eSteering); - auto towerSteeringComponent = m_World->GetComponent(tankSteeringComponent->Turret); auto barrelSteeringComponent = m_World->GetComponent(tankSteeringComponent->Barrel); @@ -65,7 +64,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit { auto tankTransform = m_World->GetComponent(entity); auto transformComponent = m_World->GetComponent(tankSteeringComponent->Barrel); - auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(tankSteeringComponent->Barrel); + glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); transformComponent->Orientation *= orientation; @@ -81,7 +80,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit transformComponent->Orientation = glm::quat(angles); } - + auto absoluteTransform = m_World->GetSystem()->AbsoluteTransform(tankSteeringComponent->Barrel); if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5) { @@ -138,7 +137,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit auto clonePhysicsComponent = m_World->GetComponent(clone); //1,670m/s //25kg - Events::ApplyPointImpulse ePointImpulse ; + Events::ApplyPointImpulse ePointImpulse; ePointImpulse.Entity = entity; ePointImpulse.Position = absoluteTransform.Position; ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f; @@ -194,39 +193,39 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) //auto otherTransform = m_World->GetComponent(otherEntity); { -// Events::CreateExplosion e; -// e.LifeTime = 3; -// e.ParticleScale.push_back(8); -// e.ParticlesToSpawn = 20; -// e.Position = shellTransform->Position; -// e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); -// e.Speed = 3; -// e.SpreadAngle = glm::pi(); -// e.spritePath = "Textures/Sprites/Smoke1.png"; -// e.Color = glm::vec4(0.6,0.6,0.6,1); -// EventBroker->Publish(e); -// e.LifeTime = 0.7; -// e.ParticleScale.push_back(12); -// e.ParticlesToSpawn = 10; -// e.Position = shellTransform->Position; -// e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); -// e.Speed = 17; -// e.SpreadAngle = glm::pi(); -// e.spritePath = "Textures/Sprites/Fire.png"; -// EventBroker->Publish(e); -// e.LifeTime = 0.2; -// e.ParticleScale.push_back(1); -// e.ParticleScale.push_back(15); -// e.ParticlesToSpawn = 5; -// e.Position = shellTransform->Position; -// e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1,0,0)); -// e.Speed = 6; -// e.SpreadAngle = glm::pi(); -// e.spritePath = "Textures/Sprites/Blast1.png"; -// e.Color = glm::vec4(2, 2, 2, 0.2); -// EventBroker->Publish(e); - Events::CreateExplosion e; + e.LifeTime = 3; + e.ParticleScale.push_back(8); + e.ParticlesToSpawn = 20; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); + e.Speed = 3; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Smoke1.png"; + e.Color = glm::vec4(0.6, 0.6, 0.6, 1); + EventBroker->Publish(e); + e.LifeTime = 0.7; + e.ParticleScale.push_back(12); + e.ParticlesToSpawn = 10; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); + e.Speed = 17; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Fire.png"; + EventBroker->Publish(e); + e.LifeTime = 0.2; + e.ParticleScale.push_back(1); + e.ParticleScale.push_back(15); + e.ParticlesToSpawn = 5; + e.Position = shellTransform->Position; + e.RelativeUpOrientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0)); + e.Speed = 6; + e.SpreadAngle = glm::pi(); + e.spritePath = "Textures/Sprites/Blast1.png"; + e.Color = glm::vec4(2, 2, 2, 0.2); + EventBroker->Publish(e); + + /*Events::CreateExplosion e; e.LifeTime = 1.5; e.ParticleScale.push_back(1); e.ParticleScale.push_back(6); @@ -253,7 +252,7 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) e.Speed = 12; e.spritePath = "Textures/Sprites/Splash.png"; e.Color = glm::vec4(1.f,1.f,1.f,1); - EventBroker->Publish(e); + EventBroker->Publish(e);*/ } { Events::PlaySFX e; @@ -263,27 +262,41 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e) EventBroker->Publish(e); } + // Direct damage + auto health = m_World->GetComponent(otherEntity); + if (health) + { + Events::Damage d; + d.Entity = otherEntity; + d.Amount = shellComponent->Damage; + EventBroker->Publish(d); + } + + // Splash damage for (auto &physComponent : *physicsComponents) { - EntityID physicsEntity = std::dynamic_pointer_cast(physComponent)->Entity; - auto physEntityTransform = m_World->GetComponent(physicsEntity); + EntityID physicsEntity = physComponent->Entity; + // No splash damage to the direct hit target + if (physicsEntity == otherEntity) + continue; + auto physEntityTransform = m_World->GetSystem()->AbsoluteTransform(physicsEntity); - float distance = glm::distance(physEntityTransform->Position, shellTransform->Position); + float distance = glm::distance(physEntityTransform.Position, shellTransform->Position); if (distance <= shellComponent->ExplosionRadius) { // DO STUFF! :D float radius = shellComponent->ExplosionRadius; float strength = (1.f - pow(distance / radius, 2)) * shellComponent->ExplosionStrength; - glm::vec3 direction = glm::normalize(physEntityTransform->Position - shellTransform->Position); + glm::vec3 direction = glm::normalize(physEntityTransform.Position - shellTransform->Position); Events::ApplyPointImpulse e; e.Entity = physicsEntity; e.Impulse = direction * strength; - e.Position = physEntityTransform->Position; + e.Position = physEntityTransform.Position; EventBroker->Publish(e); auto health = m_World->GetComponent(physicsEntity); - if(health) + if (health && health->VulnerableToSplash) { Events::Damage d; d.Entity = physicsEntity; @@ -513,8 +526,8 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID) modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; auto tankShellComponent = m_World->AddComponent(shot); tankShellComponent->Damage = 20.f; - tankShellComponent->ExplosionRadius = 30.f; - tankShellComponent->ExplosionStrength = 300000.f; + tankShellComponent->ExplosionRadius = 20.f; + tankShellComponent->ExplosionStrength = 140.f; { auto shape = m_World->CreateEntity(shot); auto transform = m_World->AddComponent(shape); diff --git a/src/Systems/WallSystem.cpp b/src/Systems/WallSystem.cpp index 73f1eaa..c9d794b 100644 --- a/src/Systems/WallSystem.cpp +++ b/src/Systems/WallSystem.cpp @@ -20,6 +20,18 @@ bool Systems::WallSystem::Damage( const Events::Damage &event ) return false; } LOG_INFO("WallSystem::Damage"); + + // Change to damage model + auto modelComponent = m_World->GetComponent(event.Entity); + auto damageModel = m_World->GetComponent(event.Entity); + if (modelComponent) + { + modelComponent->ModelFile = damageModel->ModelFile; + modelComponent->Color = damageModel->Color; + modelComponent->ShadowCaster = damageModel->ShadowCaster; + modelComponent->Transparent = damageModel->Transparent; + } + auto wallhealthcomponent = m_World->GetComponent(event.Entity); if(wallhealthcomponent->Amount > 0) { @@ -29,6 +41,7 @@ bool Systems::WallSystem::Damage( const Events::Damage &event ) //auto transformComponent = m_World->GetComponent(event.Entity); Components::Transform transformComponent = m_World->GetSystem()->AbsoluteTransform(event.Entity); + // Spawn debris for(auto d : wallComponent->Walldebris) { auto debris = m_World->CloneEntity(d); diff --git a/src/Systems/WallSystem.h b/src/Systems/WallSystem.h index 84e5972..6dbdea6 100644 --- a/src/Systems/WallSystem.h +++ b/src/Systems/WallSystem.h @@ -8,6 +8,7 @@ #include "Events/Damage.h" #include "Events/ApplyPointImpulse.h" #include "Components/Model.h" +#include "Components/DamageModel.h" #include "Components/Wall.h" #include "Components/Transform.h" #include "Components/Physics.h" diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index a7ddc7e..eddc0a6 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -139,6 +139,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 6219aaf..71d2baf 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -74,7 +74,6 @@ Game\Systems - Game\Systems @@ -84,11 +83,18 @@ Audio - - Physics\Systems + + Game\Systems + + + Physics\Systems + + + Game\Systems + @@ -573,10 +579,6 @@ Game\Components - - - - Game\Components @@ -612,6 +614,21 @@ Game\Events + + Game\Events + + + Physics\Events + + + Physics\Components + + + Game\Systems + + + Rendering\Components +