Direct damage and VulnerableToSplash flag on Health component

This commit is contained in:
2014-06-04 23:54:52 +02:00
parent 2d716e2998
commit 56e6545f0f
11 changed files with 141 additions and 60 deletions
+27
View File
@@ -0,0 +1,27 @@
#ifndef Components_DamageModel_h__
#define Components_DamageModel_h__
#include <string>
#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__
+4 -1
View File
@@ -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); }
};
+10 -7
View File
@@ -650,9 +650,12 @@ EntityID GameWorld::CreateWall(EntityID parent, glm::vec3 pos, glm::quat orienta
auto model = AddComponent<Components::Model>(wall);
model->ModelFile = "Models/Wall/WallWhole/Wall.obj";
auto damageModel = AddComponent<Components::DamageModel>(wall);
damageModel->ModelFile = "Models/Wall/WallWhole/WallCracks.obj";
auto health = AddComponent<Components::Health>(wall);
health->Amount = 50.f;
health->VulnerableToSplash = false;
auto shape = CreateEntity(wall);
auto shapetransform = AddComponent<Components::Transform>(shape);
@@ -752,7 +755,7 @@ void GameWorld::CreateTerrain()
}
CreateBase(glm::quat(), 1);
//CreateBase(glm::quat(glm::vec3(0, glm::pi<float>(), 0)), 2);
CreateBase(glm::quat(glm::vec3(0, glm::pi<float>(), 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<float>() / 2.f, 0)), teamID);
CreateWall(base, glm::vec3(273.f, 40.3f, -55.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
//CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -45.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -35.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, -15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, 15.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateWall(base, glm::vec3(273.f, 40.3f, 25.f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)), teamID);
}
+1
View File
@@ -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"
+1
View File
@@ -4,6 +4,7 @@
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Health>([]() { return new Components::Health(); });
cf->Register<Components::DamageModel>([]() { return new Components::DamageModel(); });
}
void Systems::DamageSystem::Initialize()
+1
View File
@@ -4,6 +4,7 @@
#include "System.h"
#include "Components/Health.h"
#include "Components/DamageModel.h"
#include "Events/Damage.h"
#include "Events/OnDead.h"
+58 -45
View File
@@ -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<Components::TowerSteering>(tankSteeringComponent->Turret);
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(tankSteeringComponent->Barrel);
@@ -65,7 +64,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
{
auto tankTransform = m_World->GetComponent<Components::Transform>(entity);
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->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<Systems::TransformSystem>()->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<Components::Physics>(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<Components::Transform>(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<float>() / 2, glm::vec3(1,0,0));
// e.Speed = 3;
// e.SpreadAngle = glm::pi<float>();
// 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<float>() / 2, glm::vec3(1,0,0));
// e.Speed = 17;
// e.SpreadAngle = glm::pi<float>();
// 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<float>() / 2, glm::vec3(1,0,0));
// e.Speed = 6;
// e.SpreadAngle = glm::pi<float>();
// 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<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
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<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
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<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
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<Components::Health>(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<Components::Physics>(physComponent)->Entity;
auto physEntityTransform = m_World->GetComponent<Components::Transform>(physicsEntity);
EntityID physicsEntity = physComponent->Entity;
// No splash damage to the direct hit target
if (physicsEntity == otherEntity)
continue;
auto physEntityTransform = m_World->GetSystem<Systems::TransformSystem>()->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<Components::Health>(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<Components::TankShell>(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<Components::Transform>(shape);
+13
View File
@@ -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<Components::Model>(event.Entity);
auto damageModel = m_World->GetComponent<Components::DamageModel>(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<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
@@ -29,6 +41,7 @@ bool Systems::WallSystem::Damage( const Events::Damage &event )
//auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
Components::Transform transformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(event.Entity);
// Spawn debris
for(auto d : wallComponent->Walldebris)
{
auto debris = m_World->CloneEntity(d);
+1
View File
@@ -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"
+1
View File
@@ -139,6 +139,7 @@
<ClInclude Include="..\..\src\Components\BlendMap.h" />
<ClInclude Include="..\..\src\Components\BoxShape.h" />
<ClInclude Include="..\..\src\Components\Camera.h" />
<ClInclude Include="..\..\src\Components\DamageModel.h" />
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
<ClInclude Include="..\..\src\Components\Flag.h" />
<ClInclude Include="..\..\src\Components\Follow.h" />
+24 -7
View File
@@ -74,7 +74,6 @@
<ClCompile Include="..\..\src\Systems\DamageSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
@@ -84,11 +83,18 @@
<ClCompile Include="..\..\src\Sound.cpp">
<Filter>Audio</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
<ClCompile Include="..\..\src\Systems\GameStateSystem.cpp" />
<ClCompile Include="..\..\src\Systems\JeepSteeringSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GameStateSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
@@ -573,10 +579,6 @@
<ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\JeepSteering.h" />
<ClInclude Include="..\..\src\Events\JeepSteer.h" />
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\Components\Team.h">
<Filter>Game\Components</Filter>
</ClInclude>
@@ -612,6 +614,21 @@
<ClInclude Include="..\..\src\Events\GameStart.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\JeepSteer.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\JeepSteering.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\DamageModel.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">