diff --git a/src/Components/TowerDebris.h b/src/Components/TowerDebris.h new file mode 100644 index 0000000..545c8dd --- /dev/null +++ b/src/Components/TowerDebris.h @@ -0,0 +1,20 @@ +#ifndef Components_TowerDebris_h__ +#define Components_TowerDebris_h__ + +#include "Component.h" +#include +#include + +namespace Components +{ + + struct TowerDebris : Component + { + std::vector TowerDebrisIDs; + + virtual TowerDebris* Clone() const override { return new TowerDebris(*this); } + }; + +} + +#endif // Components_TowerDebris_h__ diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index e50594c..85166b1 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -112,6 +112,51 @@ void GameWorld::Initialize() EventBroker->Publish(e); } +#pragma region Tower_Debris_Template + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.f, 4.12801f, 1.18125f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Turret/Gun/Gun.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Turret/Gun/Gun.obj"; + + m_TowerDebrisTemplates.push_back(debri); + } + + { + auto debri = CreateEntity(); + AddComponent(debri); + auto transform = AddComponent(debri); + transform->Position = glm::vec3(0.f, 5.889f-0.92791f, 0.f); + auto model = AddComponent(debri); + model->ModelFile = "Models/Turret/GunRotation/GunRotation.obj"; + auto physics = AddComponent(debri); + physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic; + physics->Mass = 200.f; + physics->Restitution = .04f; + physics->Friction = 0.9f; + + auto shape = CreateEntity(debri); + auto shapetransform = AddComponent(shape); + auto shapemesh = AddComponent(shape); + shapemesh->ResourceName = "Models/Turret/GunRotation/GunRotation.obj"; + + m_TowerDebrisTemplates.push_back(debri); + } + +#pragma endregion + #pragma region Wall_Debris_Template { @@ -734,6 +779,9 @@ EntityID GameWorld::CreateTower(EntityID parent, glm::vec3 pos, int teamID) turretComponent->ShotTemplate = m_ShotTemplate; turretComponent->ShotSpeed = 40.f; + auto debrisComponent = AddComponent(towerBase); + debrisComponent->TowerDebrisIDs = m_TowerDebrisTemplates; + CommitEntity(towerBase); return towerBase; @@ -1330,7 +1378,7 @@ void GameWorld::CreateBase(glm::quat orientation, int teamID) 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))); - CreateTower(base, glm::vec3(290.f, 40.3f, 15.f), teamID); + //CreateTower(base, glm::vec3(290.f, 40.3f, 15.f), teamID); // -Z CreateWall(base, glm::vec3(280.f, 40.3f, -62.f), glm::quat(glm::vec3(0, 0, 0))); @@ -1363,6 +1411,13 @@ void GameWorld::CreateBase(glm::quat orientation, int teamID) CreateWall(base, glm::vec3(340.f, 40.3f, 32.f), glm::quat(glm::vec3(0, 0, 0))); CreateWall(base, glm::vec3(350.f, 40.3f, 32.f), glm::quat(glm::vec3(0, 0, 0))); + CreateTower(base, glm::vec3(273.01227f, 40.43885f, 32.99123f), teamID); + CreateTower(base, glm::vec3(273.01227f, 40.30102f, -62.82098f), teamID); + CreateTower(base, glm::vec3(357.36978f, 40.43885f, -62.82098f), teamID); + CreateTower(base, glm::vec3(357.36978f, 40.43885f, 32.99123f), teamID); + CreateTower(base, glm::vec3(119.64996f, 28.90156f, 16.63123f), teamID); + CreateTower(base, glm::vec3(119.05541f, 29.54314f, 18.33529f), teamID); + CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0)), teamID); CreateFlag(base, glm::vec3(291.f, 41.7412f, -36.2f), glm::quat(glm::vec3(0, glm::pi() / 2.f, 0)), teamID); diff --git a/src/GameWorld.h b/src/GameWorld.h index 9a2ff76..84806d2 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -94,6 +94,7 @@ private: void CreateBase(glm::quat orientation, int playerID); void CreateFlag(EntityID parent, glm::vec3 position, glm::quat orientation, int TeamID); std::vector m_WallDebrisTemplates; + std::vector m_TowerDebrisTemplates; EntityID m_ShotTemplate; }; diff --git a/src/Systems/TowerSystem.cpp b/src/Systems/TowerSystem.cpp index 0c992e0..92022b1 100644 --- a/src/Systems/TowerSystem.cpp +++ b/src/Systems/TowerSystem.cpp @@ -7,12 +7,15 @@ void Systems::TowerSystem::RegisterComponents( ComponentFactory* cf ) cf->Register([]() { return new Components::Tower(); }); cf->Register([]() { return new Components::Turret(); }); cf->Register([]() {return new Components::TurretShot(); }); + cf->Register([]() {return new Components::TowerDebris(); }); } void Systems::TowerSystem::Initialize() { //EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage); EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TowerSystem::OnCollision); + EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage); + Temp_m_TimeSinceLastShot = 0; } @@ -21,6 +24,58 @@ void Systems::TowerSystem::Update( double dt ) } +bool Systems::TowerSystem::Damage( const Events::Damage &event ) +{ + auto debrisComponent = m_World->GetComponent(event.Entity); + if(!debrisComponent) + { + return false; + } + LOG_INFO("TowerSystem::Damage"); + + // Change to damage model + + auto wallhealthcomponent = m_World->GetComponent(event.Entity); + if(wallhealthcomponent->Amount > 0) + { + return false; + } + LOG_INFO("Entity %i is dead", event.Entity); + auto entitytransform = m_World->GetComponent(event.Entity); + if(!entitytransform) + return false; + //auto transformComponent = m_World->GetComponent(event.Entity); + Components::Transform transformComponent = m_World->GetSystem()->AbsoluteTransform(event.Entity); + + // Spawn debris + for(auto d : debrisComponent->TowerDebrisIDs) + { + auto debris = m_World->CloneEntity(d); + + auto transform = m_World->GetComponent(debris); + Components::Transform absolutetransformComponent = m_World->GetSystem()->AbsoluteTransform(debris); + transform->Orientation = transform->Orientation * transformComponent.Orientation; + transform->Position = transform->Orientation * transform->Position + transformComponent.Position; + + //DO STUFF! :D + float distance = glm::distance(transform->Position, transformComponent.Position); + float radius = 15.f; + float strength = (1.f - pow(distance / radius, 2)) * 2000.f; + glm::vec3 direction = glm::normalize(transformComponent.Position - transform->Position); + + Events::ApplyPointImpulse e; + e.Entity = debris; + e.Impulse = direction * strength; + e.Position = transformComponent.Position; + EventBroker->Publish(e); + + } + + entitytransform->Position = glm::vec3(0.f, -50000000.f, 0.f); + + return true; +} + void Systems::TowerSystem::UpdateEntity( double dt, EntityID entity, EntityID parent ) { auto towerComponent = m_World->GetComponent(entity); @@ -48,7 +103,7 @@ void Systems::TowerSystem::UpdateEntity( double dt, EntityID entity, EntityID pa for(auto player : *players) { auto playerComponent = std::dynamic_pointer_cast(player); - if(towerComponent->ID != playerComponent->ID) //!= betyder att den bara targetar sitt eget lag, == fienden. + if(towerComponent->ID == playerComponent->ID) //!= betyder att den bara targetar sitt eget lag, == fienden. continue; auto playerTransform = m_World->GetComponent(player->Entity); diff --git a/src/Systems/TowerSystem.h b/src/Systems/TowerSystem.h index bf9b65d..b2fe2ff 100644 --- a/src/Systems/TowerSystem.h +++ b/src/Systems/TowerSystem.h @@ -9,10 +9,14 @@ #include "Components/Turret.h" #include "Components/TurretShot.h" #include "Components/Health.h" +#include "Components/TowerDebris.h" +#include "Components/Model.h" #include "Events/SetVelocity.h" #include "Events/CreateExplosion.h" #include "Events/Collision.h" #include "Events/Damage.h" +#include "Events/ApplyPointImpulse.h" + @@ -37,6 +41,8 @@ namespace Systems EventRelay m_ECollision; bool OnCollision(const Events::Collision &e); + EventRelay m_eDamage; + bool Damage(const Events::Damage &event); private: diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index c4a2431..daac8ae 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -152,6 +152,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 00ecabc..b6c10c1 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -1,736 +1,226 @@  - - - - - - - Rendering\Systems - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Physics\Systems - - - Base\Systems - - - Base\Systems - - - Audio\Systems - - - Input\Systems - - - Input\Systems - - - - Particle System\Systems - + + - - Physics - - - Input - - - Physics\Systems - - - Game\Vehicles\Helicopter\Systems - - - Physics\Systems - - - Base\Systems - - - Game\Systems - - - Game\Systems - - - Game\Systems - - - Audio - - - Physics\Systems - - - Game\Systems - - - Game\Systems - - - Game\Systems - - - Physics\Systems - - - Game\Systems - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Game\Systems - - {ce43847c-9745-46d2-b000-069af4882886} - - - {8974329a-5c12-4b94-86e7-5931555bc129} - - - {aca514ec-84de-423c-a270-ec4399904c5a} - - - {fcbc3469-7049-4c07-9d76-f8f1e872f042} - - - {f6c5fd1d-7180-42b7-b973-a91bfc3ea189} - - - {d08cc18b-b7d8-47a7-91af-7283052e4c97} - - - {1c5d571e-55f4-498b-b64a-2f28ac2cd9b0} - - - {635843f6-c94e-4798-8201-db64d11e2a03} - - - {3bd82924-397c-4c5a-959c-971612269374} - - - {c17ff66a-f9f5-4329-a05d-e7bf8a140dd3} - - - {caa1e07f-fa19-4706-bf59-de74a0290763} - - - {444e18d8-8ab6-413b-b9b0-59a6309e0511} - - - {a2db813b-1d08-4d48-97ac-2faaff29a1cc} - - - {44c41b41-b706-4d88-8d50-abdeb2a828fe} - - - {30c6d948-459c-4fc7-b44d-ecbe5f34203e} - - - {8bcc0a31-3e0d-4342-8d10-ec8edfa03abd} - - - {93ce6550-7614-46b4-a554-0eec26e6fbf6} - - - {0bb544bb-1b0a-487f-88d6-f8ab8a2795f4} - - - {a6ca6194-3aa5-46cc-ac05-206f9a400dec} - - - {9f45f029-46c8-4c0d-b44c-dc9bffd3c6a6} - - - {6e633434-4aed-453d-b2f9-8c51ca7f78db} - - - {85692f3a-5241-4780-a3ca-f4d8a2851392} - - - {ee125b77-b275-4841-abc9-374957a89916} - - - {42ae084f-ade8-402c-87ba-f03f6b846bc8} - - - {a025d51e-594d-4844-983b-f683726bf1bf} - - - {ffab6cc2-2fbf-400f-9398-a6741b6cc95c} - - - {5b992473-73e6-485e-8f13-17e0801fb2ca} - - - {8a78be3a-a3c5-4054-a2f1-1456f3fcbab0} - - - {8ccc0abe-5bdd-4656-ab11-5708a39c71ae} - - - {b2416d05-a49e-4fef-a5c4-cd03d8cc2efd} - - - {b34c0c95-a887-4cf4-af24-cf7c1f459aa8} - - - {cb06b441-90b8-46ed-b347-4190dac7185b} - - - {ddd3c442-7c2f-4690-9308-fcef62deee0b} - - - {3c2ea0e5-41a1-4b11-a891-1d59ead7223c} - - - {3cbe68d9-2446-45ee-8637-ffb805997dcd} - - - {a025d51e-594d-4844-983b-f683726bf1bf} - - - {9702064a-02a2-4b3c-a2ab-47c23a9cf49c} - - - - - - - - - - - Util - - - Util - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - Rendering\Components - - - Rendering\Components - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Rendering - - - Physics\Components - - - Physics\Systems - - - Base\Components - - - Base\Components - - - Rendering\Components - - - Base\Systems - - - Base\Systems - - - Audio\Systems - - - Audio\Components - - - Rendering\Systems - - - Input\Systems - - - Input\Systems - - - Input\Components - - - Input\Components - - - Particle System\Components - - - Rendering\Components - - - Rendering\Components - - - - Audio - - - Physics\Components - - - Physics\Components - - - Physics - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Util - - - Physics\Components - - - Physics\Components - - - Physics\Components - - - Particle System\Systems - - - Particle System\Components - - - GUI - - - Util - - - - Input\Events - - - Input\Events - - - Input - - - Input\Events - - - Input\Events - - - Input\Events - - - Input\Events - - - Input\Events - - - Input\Events - - - Input - - - Rendering - - - GUI - - - Physics - - - Physics\Components - - - Physics\Events - - - Physics\Systems - - - Physics\Components - - - Physics\Components - - - Physics\Events - - - Input\Events - - - Input\Events - - - Input\Events - - - Input\Events - - - Physics\Components - - - Physics\Components - - - Input\Events - - - Game\Vehicles\Helicopter\Components - - - Game\Vehicles\Helicopter\Systems - - - Physics\Events - - - Physics\Events - - - Game\Components - - - Particle System\Events - - - Physics\Events - - - Gameplay\Components - - - Audio\Components - - - Base\Events - - - Audio\Events - - - Audio\Events - - - Audio\Events - - - Physics\Components - - - Physics\Events - - - Physics\Events - - - Physics\Components - - - Physics\Systems - - - Physics\Components - - - Physics\Events - - - Base\Systems - - - Base\Components - - - Base\Components - - - Game\Systems - - - Game\Events - - - Game\Components - - - GUI - - - GUI - - - Rendering\Events - - - GUI - - - GUI - - - GUI - - - Physics\Systems - - - Base\Events - - - Rendering\Components - - - Physics\Events - - - Game\Components - - - Game\Systems - - - Base\Events - - - Physics\Components - - - Physics\Components - - - Game\Systems - - - Game\Components - - - Base\Components - - - Base\Components - - - Rendering\Components - - - GUI - - - Game\Events - - - Game\Components - - - Game\Components - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - Game\Systems - - - Game\Systems - - - Game\Components - - - Game\Components - - - Physics\Components - - Game\Components - - - Physics\Systems - - - - GUI - - - Game\Systems - - - Game\Events - - - Game\Events - - - Game\Events - - - Game\Events - - - Game\Events - - - GUI - - - Game\Events - - - Game\Events - - - Physics\Events - - - Physics\Components - - - Game\Systems - - - Rendering\Components - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Game\Systems - + + + + + + + + - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - - - Shaders - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file