From fe6fd0bbe35005f87f32dbd3853193423229c748 Mon Sep 17 00:00:00 2001 From: verysecrethero Date: Fri, 5 Feb 2016 15:15:04 +0100 Subject: [PATCH] PickupSpawnSystem now spawns a new HealthPickup after the respawnTimer is up. Added HealthPickup.xml entity. Event PickupSpawned now gets published when a new HealthPickup spawns. Player now gains health as he picks up the HealthPickup. --- include/Engine/Core/EPickupSpawned.h | 2 +- include/Engine/Core/EPickupTaken.h | 19 -- include/Game/Systems/PickupSpawnSystem.h | 16 ++ resources/Schema/Components.xsd | 2 +- resources/Schema/Components/HealthPickup.xml | 4 + resources/Schema/Components/HealthPickup.xsd | 18 ++ resources/Schema/Components/PickupSpawn.xml | 2 - resources/Schema/Components/PickupSpawn.xsd | 11 - resources/Schema/Entities/CapturePoint.xml | 2 +- resources/Schema/Entities/HealthPickup.xml | 18 ++ .../Schema/Entities/HealthPickupTest.xml | 257 ++++++++++++++++++ src/Game/Game.cpp | 2 + src/Game/Systems/PickupSpawnSystem.cpp | 50 ++++ 13 files changed, 368 insertions(+), 35 deletions(-) delete mode 100644 include/Engine/Core/EPickupTaken.h create mode 100644 resources/Schema/Components/HealthPickup.xml create mode 100644 resources/Schema/Components/HealthPickup.xsd delete mode 100644 resources/Schema/Components/PickupSpawn.xml delete mode 100644 resources/Schema/Components/PickupSpawn.xsd create mode 100644 resources/Schema/Entities/HealthPickup.xml create mode 100644 resources/Schema/Entities/HealthPickupTest.xml diff --git a/include/Engine/Core/EPickupSpawned.h b/include/Engine/Core/EPickupSpawned.h index acb6776e..dc3bc632 100644 --- a/include/Engine/Core/EPickupSpawned.h +++ b/include/Engine/Core/EPickupSpawned.h @@ -10,7 +10,7 @@ namespace Events struct PickupSpawned : Event { EntityID PickupID; - EntityWrapper Spawner; + EntityWrapper Pickup; }; } diff --git a/include/Engine/Core/EPickupTaken.h b/include/Engine/Core/EPickupTaken.h deleted file mode 100644 index e06fd974..00000000 --- a/include/Engine/Core/EPickupTaken.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef EPickupTaken_h__ -#define EPickupTaken_h__ - -#include "Core/Event.h" -#include "Core/EntityWrapper.h" - -namespace Events -{ - -struct PickupTaken : Event -{ - EntityID PickupID; - EntityWrapper Spawner; - EntityWrapper Player; -}; - -} - -#endif \ No newline at end of file diff --git a/include/Game/Systems/PickupSpawnSystem.h b/include/Game/Systems/PickupSpawnSystem.h index 99dad0aa..8ae07265 100644 --- a/include/Game/Systems/PickupSpawnSystem.h +++ b/include/Game/Systems/PickupSpawnSystem.h @@ -9,9 +9,25 @@ #include "Rendering/ESetCamera.h" #include "Core/ConfigFile.h" #include "Core/EPickupSpawned.h" +#include "Core/EPlayerHealthPickup.h"; +#include "Engine/Collision/ETrigger.h" + +#include "Common.h" +#include class PickupSpawnSystem : public ImpureSystem { +public: + PickupSpawnSystem(World* world, EventBroker* eventBroker); + + virtual void Update(double dt) override; + +private: + EventRelay m_ETriggerTouch; + bool OnTriggerTouch(Events::TriggerTouch& e); + + std::vector> m_ETriggerTouchVector; + }; #endif diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd index 445d96e7..996475cf 100644 --- a/resources/Schema/Components.xsd +++ b/resources/Schema/Components.xsd @@ -29,5 +29,5 @@ - + \ No newline at end of file diff --git a/resources/Schema/Components/HealthPickup.xml b/resources/Schema/Components/HealthPickup.xml new file mode 100644 index 00000000..e9d0a23d --- /dev/null +++ b/resources/Schema/Components/HealthPickup.xml @@ -0,0 +1,4 @@ + + + 3 + \ No newline at end of file diff --git a/resources/Schema/Components/HealthPickup.xsd b/resources/Schema/Components/HealthPickup.xsd new file mode 100644 index 00000000..db9661a7 --- /dev/null +++ b/resources/Schema/Components/HealthPickup.xsd @@ -0,0 +1,18 @@ + + + + + + + + A Health Pickup + + + + + The respawn timer for a health pickup + + + + + diff --git a/resources/Schema/Components/PickupSpawn.xml b/resources/Schema/Components/PickupSpawn.xml deleted file mode 100644 index f8ce1225..00000000 --- a/resources/Schema/Components/PickupSpawn.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/resources/Schema/Components/PickupSpawn.xsd b/resources/Schema/Components/PickupSpawn.xsd deleted file mode 100644 index 7ab90407..00000000 --- a/resources/Schema/Components/PickupSpawn.xsd +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - Combined with a Spawner, defines a spawn point for a pickup - - - diff --git a/resources/Schema/Entities/CapturePoint.xml b/resources/Schema/Entities/CapturePoint.xml index 9b3c5036..9f33c4de 100644 --- a/resources/Schema/Entities/CapturePoint.xml +++ b/resources/Schema/Entities/CapturePoint.xml @@ -5,7 +5,7 @@ - C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh + Models/Core/UnitSphere.mesh diff --git a/resources/Schema/Entities/HealthPickup.xml b/resources/Schema/Entities/HealthPickup.xml new file mode 100644 index 00000000..f1b787f6 --- /dev/null +++ b/resources/Schema/Entities/HealthPickup.xml @@ -0,0 +1,18 @@ + + + + + + + + Models/Core/UnitSphere.mesh + + + + + + + + + + diff --git a/resources/Schema/Entities/HealthPickupTest.xml b/resources/Schema/Entities/HealthPickupTest.xml new file mode 100644 index 00000000..6a368006 --- /dev/null +++ b/resources/Schema/Entities/HealthPickupTest.xml @@ -0,0 +1,257 @@ + + + + + + + + + + + + Models\MapVersion1.mesh + + + + + + + + + 2 + + + Models/DirectionalLightWidget.mesh + false + + + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + 8 + 2.7999999523162842 + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitCube.mesh + false + + + Schema/Entities/Player.xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Models/Core/UnitSphere.mesh + + + + + + + + + + + diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index f5afcaeb..9e803e9e 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -10,6 +10,7 @@ #include "Systems/PlayerSpawnSystem.h" #include "Core/EntityFileWriter.h" #include "Game/Systems/CapturePointSystem.h" +#include "Game/Systems/PickupSpawnSystem.h" #include "Game/Systems/WeaponSystem.h" #include "Game/Systems/PlayerHUD.h" #include "Game/Systems/LifetimeSystem.h" @@ -91,6 +92,7 @@ Game::Game(int argc, char* argv[]) m_SystemPipeline->AddSystem(updateOrderLevel, m_Renderer); m_SystemPipeline->AddSystem(updateOrderLevel); m_SystemPipeline->AddSystem(updateOrderLevel); + m_SystemPipeline->AddSystem(updateOrderLevel); // Populate Octree with collidables ++updateOrderLevel; m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision, "Collidable"); diff --git a/src/Game/Systems/PickupSpawnSystem.cpp b/src/Game/Systems/PickupSpawnSystem.cpp index 3b758764..28f0ca86 100644 --- a/src/Game/Systems/PickupSpawnSystem.cpp +++ b/src/Game/Systems/PickupSpawnSystem.cpp @@ -1 +1,51 @@ #include "Systems/PickupSpawnSystem.h" + +PickupSpawnSystem::PickupSpawnSystem(World* m_World, EventBroker* eventBroker) + : System(m_World, eventBroker) +{ + EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &PickupSpawnSystem::OnTriggerTouch); +} + +void PickupSpawnSystem::Update(double dt) +{ + for (auto &healthPickupPosition : m_ETriggerTouchVector) { + //set the double timer value (1) + std::get<1>(healthPickupPosition) -= dt; + if (std::get<1>(healthPickupPosition) < 0) { + //spawn and delete the vector item + auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); + EntityFileParser parser(entityFile); + EntityID healthPickupID = parser.MergeEntities(m_World); + + //let the world know a pickup has spawned (graphics effects, etc) + Events::PickupSpawned ePickupSpawned; + ePickupSpawned.PickupID = healthPickupID; + ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID); + m_EventBroker->Publish(ePickupSpawned); + + //erase the current element (healthPickupPosition) + m_ETriggerTouchVector.erase(std::remove(m_ETriggerTouchVector.begin(), m_ETriggerTouchVector.end(),healthPickupPosition), m_ETriggerTouchVector.end()); + break; + } + } +} + + +bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e) +{ + if (!e.Trigger.HasComponent("HealthPickup")) { + return false; + } + //personEntered = e.Entity, thingEntered = e.Trigger + Events::PlayerHealthPickup ePlayerHealthPickup; + ePlayerHealthPickup.HealthAmount = 30.0f; + ePlayerHealthPickup.PlayerHealedID = e.Entity.ID; + m_EventBroker->Publish(ePlayerHealthPickup); + + //copy the position to a vector -> respawntimer in ["HealthPickup"]["RespawnTimer"] + m_ETriggerTouchVector.push_back(std::make_tuple((glm::vec3)e.Trigger["Transform"]["Position"], e.Trigger["HealthPickup"]["RespawnTimer"])); + + //delete the healthpickup + m_World->DeleteEntity(e.Trigger.ID); + return true; +}