Rockets deleted properly
This commit is contained in:
@@ -9,10 +9,11 @@ namespace Components
|
||||
struct Physics : Component
|
||||
{
|
||||
Physics()
|
||||
: Mass(0.f), Static(false){}
|
||||
: Mass(1.f), Static(false), Phantom(false){}
|
||||
|
||||
float Mass;
|
||||
bool Static;
|
||||
bool Phantom;
|
||||
|
||||
virtual Physics* Clone() const override { return new Physics(*this); }
|
||||
};
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef Components_TankShell_h__
|
||||
#define Components_TankShell_h__
|
||||
|
||||
#include "Component.h"
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct TankShell : Component
|
||||
{
|
||||
TankShell()
|
||||
: Damage(1.0f){ }
|
||||
|
||||
float Damage;
|
||||
|
||||
virtual TankShell* Clone() const override { return new TankShell(*this); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Components_TankShell_h__
|
||||
+14
-7
@@ -258,7 +258,8 @@ void GameWorld::Initialize()
|
||||
auto tankSteering = AddComponent<Components::TankSteering>(tank);
|
||||
tankSteering->Player = player1;
|
||||
AddComponent<Components::Input>(tank);
|
||||
|
||||
auto health = AddComponent<Components::Health>(tank);
|
||||
health->health = 1;
|
||||
{
|
||||
auto shape = CreateEntity(tank);
|
||||
auto transform = AddComponent<Components::Transform>(shape);
|
||||
@@ -312,7 +313,8 @@ void GameWorld::Initialize()
|
||||
physics->Static = false;
|
||||
auto modelComponent = AddComponent<Components::Model>(shot);
|
||||
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
||||
|
||||
auto tankShellComponent = AddComponent<Components::TankShell>(shot);
|
||||
tankShellComponent->Damage = 20.f;
|
||||
{
|
||||
auto shape = CreateEntity(shot);
|
||||
auto transform = AddComponent<Components::Transform>(shape);
|
||||
@@ -361,7 +363,7 @@ void GameWorld::Initialize()
|
||||
// auto wheelpair = CreateEntity(tank);
|
||||
// SetProperty(wheelpair, "Name", "WheelPair");
|
||||
// AddComponent(wheelpair, "WheelPairThingy");
|
||||
|
||||
#pragma region Wheels
|
||||
//Create wheels
|
||||
float wheelOffset = 0.4f;
|
||||
float springLength = 0.3f;
|
||||
@@ -658,6 +660,7 @@ void GameWorld::Initialize()
|
||||
emitterComponent->ParticleTemplate = particleEntity;
|
||||
CommitEntity(particleEntity);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
CommitEntity(tank);
|
||||
}
|
||||
@@ -677,7 +680,8 @@ void GameWorld::Initialize()
|
||||
auto tankSteering = AddComponent<Components::TankSteering>(tank);
|
||||
tankSteering->Player = player2;
|
||||
AddComponent<Components::Input>(tank);
|
||||
|
||||
auto health = AddComponent<Components::Health>(tank);
|
||||
health->health = 1;
|
||||
{
|
||||
auto shape = CreateEntity(tank);
|
||||
auto transform = AddComponent<Components::Transform>(shape);
|
||||
@@ -731,7 +735,8 @@ void GameWorld::Initialize()
|
||||
physics->Static = false;
|
||||
auto modelComponent = AddComponent<Components::Model>(shot);
|
||||
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
||||
|
||||
auto tankShellComponent = AddComponent<Components::TankShell>(shot);
|
||||
tankShellComponent->Damage = 20.f;
|
||||
{
|
||||
auto shape = CreateEntity(shot);
|
||||
auto transform = AddComponent<Components::Transform>(shape);
|
||||
@@ -780,6 +785,7 @@ void GameWorld::Initialize()
|
||||
// auto wheelpair = CreateEntity(tank);
|
||||
// SetProperty(wheelpair, "Name", "WheelPair");
|
||||
// AddComponent(wheelpair, "WheelPairThingy");
|
||||
#pragma region Wheels
|
||||
|
||||
//Create wheels
|
||||
float wheelOffset = 0.4f;
|
||||
@@ -1076,7 +1082,7 @@ void GameWorld::Initialize()
|
||||
|
||||
CommitEntity(particleEntity);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
CommitEntity(tank);
|
||||
}
|
||||
|
||||
@@ -1104,7 +1110,7 @@ void GameWorld::Initialize()
|
||||
CommitEntity(entity);
|
||||
}*/
|
||||
|
||||
for(int i = 0; i < 1; i++)
|
||||
for(int i = 0; i < 0; i++)
|
||||
{
|
||||
for (int y = 0; y < 15; y++)
|
||||
{
|
||||
@@ -1180,6 +1186,7 @@ void GameWorld::RegisterComponents()
|
||||
m_ComponentFactory.Register<Components::Transform>([]() { return new Components::Transform(); });
|
||||
m_ComponentFactory.Register<Components::Template>([]() { return new Components::Template(); });
|
||||
m_ComponentFactory.Register<Components::Player>([]() { return new Components::Player(); });
|
||||
m_ComponentFactory.Register<Components::Health>([]() { return new Components::Health(); });
|
||||
}
|
||||
|
||||
void GameWorld::RegisterSystems()
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "Components/TowerSteering.h"
|
||||
#include "Components/BarrelSteering.h"
|
||||
#include "Components/Player.h"
|
||||
#include "Components/Health.h"
|
||||
|
||||
class GameWorld : public World
|
||||
{
|
||||
|
||||
@@ -122,6 +122,7 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
cf->Register<Components::MeshShape>([]() { return new Components::MeshShape(); });
|
||||
cf->Register<Components::HingeConstraint>([]() { return new Components::HingeConstraint(); });
|
||||
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
|
||||
cf->Register<Components::TankShell>([]() { return new Components::TankShell(); });
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
@@ -159,7 +160,6 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static const double timestep = 1 / 60.0;
|
||||
@@ -580,14 +580,18 @@ bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpuls
|
||||
|
||||
void Systems::PhysicsSystem::OnEntityRemoved( EntityID entity )
|
||||
{
|
||||
// TODO:
|
||||
/*auto rigidBodyIt = m_RigidBodies.find(entity);
|
||||
if (rigidBodyIt == m_RigidBodies.end())
|
||||
return;
|
||||
|
||||
auto rigidBody = rigidBodyIt->second;
|
||||
m_RigidBodies.erase(entity);
|
||||
m_RigidBodyEntities.erase(rigidBody);
|
||||
rigidBody->removeReference();*/
|
||||
|
||||
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||
{
|
||||
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
m_RigidBodies.erase(entity);
|
||||
}
|
||||
if(m_Vehicles.find(entity) != m_Vehicles.end())
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_Vehicles[entity]->removeFromWorld();
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
}
|
||||
|
||||
+32
-11
@@ -76,7 +76,8 @@
|
||||
|
||||
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
|
||||
|
||||
#include "Components/Model.h"
|
||||
#include "Components/TankShell.h"
|
||||
#include <Physics2012/Collide/Shape/Misc/PhantomCallback/hkpPhantomCallbackShape.h>
|
||||
namespace Systems
|
||||
{
|
||||
class PhysicsSystem : public System
|
||||
@@ -94,27 +95,47 @@ public:
|
||||
EntityID entity1 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(0)];
|
||||
EntityID entity2 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(1)];
|
||||
|
||||
m_PhysicsSystem->m_PhysicsWorld->unmarkForRead();
|
||||
Events::Collision e;
|
||||
e.Entity1 = entity1;
|
||||
e.Entity2 = entity2;
|
||||
m_PhysicsSystem->EventBroker->Publish(e);
|
||||
|
||||
auto modelComponent = m_PhysicsSystem->m_World->GetComponent<Components::Model>(entity1);
|
||||
|
||||
if (modelComponent && modelComponent->ModelFile == "Models/Placeholders/rocket/Rocket.obj" && entity2 == 6)
|
||||
{
|
||||
m_PhysicsSystem->m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsSystem->m_RigidBodies[entity1]->setPosition(hkVector4(2000, -2000, 2000));
|
||||
m_PhysicsSystem->m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
m_PhysicsSystem->m_PhysicsWorld->markForRead();
|
||||
}
|
||||
|
||||
private:
|
||||
Systems::PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
friend class MyCollisionResolution;
|
||||
|
||||
/*class PhantomCallbackShape: public hkpPhantomCallbackShape
|
||||
{
|
||||
public:
|
||||
|
||||
PhantomCallbackShape(Systems::PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
virtual void phantomEnterEvent( const hkpCollidable* collidableA, const hkpCollidable* collidableB, const hkpCollisionInput& env )
|
||||
{
|
||||
Events::ApplyPointImpulse e;
|
||||
e.Entity = m_PhysicsSystem->m_RigidBodyEntities[hkpGetRigidBody(collidableB)];
|
||||
e.Position = HKVECTOR4_TO_GLMVEC3(hkpGetRigidBody(collidableB)->getPosition());
|
||||
|
||||
glm::vec3 impulse;
|
||||
impulse = HKVECTOR4_TO_GLMVEC3(hkpGetRigidBody(collidableA)->getPosition()) - HKVECTOR4_TO_GLMVEC3(hkpGetRigidBody(collidableB)->getPosition());
|
||||
e.Impulse = impulse;
|
||||
}
|
||||
|
||||
virtual void phantomLeaveEvent( const hkpCollidable* collidableA, const hkpCollidable* collidableB )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
Systems::PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
friend class PhantomCallbackShape;
|
||||
*/
|
||||
PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
|
||||
@@ -97,26 +97,40 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
|
||||
bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
|
||||
{
|
||||
// TODO:
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(e.Entity1);
|
||||
|
||||
if (modelComponent && modelComponent->ModelFile == "Models/Placeholders/rocket/Rocket.obj")
|
||||
if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity1))
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(e.Entity1);
|
||||
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(
|
||||
transform->Position,
|
||||
1,
|
||||
60,
|
||||
"Textures/Sprites/NewtonTreeDeleteASAPPlease.png",
|
||||
glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)),
|
||||
40,
|
||||
glm::pi<float>(),
|
||||
0.5f
|
||||
);
|
||||
//m_World->RemoveEntity(e.Entity1);
|
||||
}
|
||||
auto tankShell1 = m_World->GetComponent<Components::TankShell>(e.Entity1);
|
||||
auto tankShell2 = m_World->GetComponent<Components::TankShell>(e.Entity2);
|
||||
|
||||
|
||||
//LOG_INFO("Ent1 %i Ent2 %i", e.Entity1, e.Entity2);
|
||||
if(tankShell1)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(e.Entity1);
|
||||
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(transform->Position, 1, 60, "Textures/Sprites/NewtonTreeDeleteASAPPlease.png", glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)), 40, glm::pi<float>(), 0.5f);
|
||||
|
||||
auto health2 = m_World->GetComponent<Components::Health>(e.Entity2);
|
||||
if(health2)
|
||||
{
|
||||
health2->health -= tankShell1->Damage;
|
||||
}
|
||||
|
||||
m_World->RemoveEntity(e.Entity1);
|
||||
}
|
||||
|
||||
if(tankShell2)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(e.Entity2);
|
||||
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(transform->Position, 1, 60, "Textures/Sprites/NewtonTreeDeleteASAPPlease.png", glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)), 40, glm::pi<float>(), 0.5f);
|
||||
|
||||
auto health1 = m_World->GetComponent<Components::Health>(e.Entity2);
|
||||
if(health1)
|
||||
{
|
||||
health1->health -= tankShell1->Damage;
|
||||
}
|
||||
|
||||
m_World->RemoveEntity(e.Entity2);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
#include "Systems/ParticleSystem.h"
|
||||
#include "InputController.h"
|
||||
|
||||
#include "Components/Health.h"
|
||||
#include "Components/TankShell.h"
|
||||
#include "Components/SphereShape.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@
|
||||
<ClInclude Include="..\..\src\Components\BarrelSteering.h" />
|
||||
<ClInclude Include="..\..\src\Components\BoxShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\Camera.h" />
|
||||
<ClInclude Include="..\..\src\Components\DamageOnTouch.h" />
|
||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
||||
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
||||
@@ -146,6 +147,7 @@
|
||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
||||
<ClInclude Include="..\..\src\Components\SphereShape.h" />
|
||||
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
||||
<ClInclude Include="..\..\src\Components\TankShell.h" />
|
||||
<ClInclude Include="..\..\src\Components\TankSteering.h" />
|
||||
<ClInclude Include="..\..\src\Components\Template.h" />
|
||||
<ClInclude Include="..\..\src\Components\TowerSteering.h" />
|
||||
|
||||
@@ -376,9 +376,6 @@
|
||||
<ClInclude Include="..\..\src\Components\Viewport.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Health.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\LockMouse.h">
|
||||
<Filter>Input\Events</Filter>
|
||||
</ClInclude>
|
||||
@@ -400,6 +397,15 @@
|
||||
<ClInclude Include="..\..\src\Events\Collision.h">
|
||||
<Filter>Physics\Events</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\Health.h">
|
||||
<Filter>Gameplay\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\DamageOnTouch.h">
|
||||
<Filter>Gameplay\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Components\TankShell.h">
|
||||
<Filter>Physics\Components</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||
|
||||
Reference in New Issue
Block a user