diff --git a/include/Game/Systems/PickupSpawnSystem.h b/include/Game/Systems/PickupSpawnSystem.h index 8ae07265..fbb2f082 100644 --- a/include/Game/Systems/PickupSpawnSystem.h +++ b/include/Game/Systems/PickupSpawnSystem.h @@ -2,16 +2,12 @@ #define PickupSpawnSystem_h__ #include "Core/System.h" -#include "Input/EInputCommand.h" -#include "Systems/SpawnerSystem.h" -#include "Events/ESpawnerSpawn.h" -#include "Core/EPlayerSpawned.h" -#include "Rendering/ESetCamera.h" -#include "Core/ConfigFile.h" +#include "Core/Transform.h" +#include "Core/ResourceManager.h" +#include "Core/EntityFileParser.h" #include "Core/EPickupSpawned.h" #include "Core/EPlayerHealthPickup.h"; #include "Engine/Collision/ETrigger.h" - #include "Common.h" #include @@ -26,8 +22,6 @@ private: EventRelay m_ETriggerTouch; bool OnTriggerTouch(Events::TriggerTouch& e); - std::vector> m_ETriggerTouchVector; - - + std::vector> m_ETriggerTouchVector; }; #endif diff --git a/resources/Schema/Components/HealthPickup.xml b/resources/Schema/Components/HealthPickup.xml index e9d0a23d..1c9ee0f4 100644 --- a/resources/Schema/Components/HealthPickup.xml +++ b/resources/Schema/Components/HealthPickup.xml @@ -1,4 +1,5 @@ 3 + 30 \ No newline at end of file diff --git a/resources/Schema/Components/HealthPickup.xsd b/resources/Schema/Components/HealthPickup.xsd index db9661a7..c5fae00f 100644 --- a/resources/Schema/Components/HealthPickup.xsd +++ b/resources/Schema/Components/HealthPickup.xsd @@ -12,6 +12,9 @@ The respawn timer for a health pickup + + How much health the player will get when he picks the healthPickup up + diff --git a/resources/Schema/Entities/HealthPickupTest.xml b/resources/Schema/Entities/HealthPickupTest.xml index 6a368006..97fd3f4d 100644 --- a/resources/Schema/Entities/HealthPickupTest.xml +++ b/resources/Schema/Entities/HealthPickupTest.xml @@ -238,20 +238,6 @@ - - - - - - Models/Core/UnitSphere.mesh - - - - - - - - diff --git a/src/Game/Systems/PickupSpawnSystem.cpp b/src/Game/Systems/PickupSpawnSystem.cpp index 28f0ca86..558aef14 100644 --- a/src/Game/Systems/PickupSpawnSystem.cpp +++ b/src/Game/Systems/PickupSpawnSystem.cpp @@ -9,9 +9,9 @@ PickupSpawnSystem::PickupSpawnSystem(World* m_World, EventBroker* eventBroker) 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) { + //set the double timer value (value 3) + std::get<3>(healthPickupPosition) -= dt; + if (std::get<3>(healthPickupPosition) < 0) { //spawn and delete the vector item auto entityFile = ResourceManager::Load("Schema/Entities/HealthPickup.xml"); EntityFileParser parser(entityFile); @@ -23,8 +23,14 @@ void PickupSpawnSystem::Update(double dt) ePickupSpawned.Pickup = EntityWrapper(m_World, healthPickupID); m_EventBroker->Publish(ePickupSpawned); + //set values from the old entity to the new entity + auto& newHealthPickupEntity = EntityWrapper(m_World, healthPickupID); + newHealthPickupEntity["Transform"]["Position"] = std::get<0>(healthPickupPosition); + newHealthPickupEntity["HealthPickup"]["HealthGain"] = std::get<1>(healthPickupPosition); + newHealthPickupEntity["HealthPickup"]["RespawnTimer"] = std::get<2>(healthPickupPosition); + //erase the current element (healthPickupPosition) - m_ETriggerTouchVector.erase(std::remove(m_ETriggerTouchVector.begin(), m_ETriggerTouchVector.end(),healthPickupPosition), m_ETriggerTouchVector.end()); + m_ETriggerTouchVector.erase(std::remove(m_ETriggerTouchVector.begin(), m_ETriggerTouchVector.end(), healthPickupPosition), m_ETriggerTouchVector.end()); break; } } @@ -38,12 +44,17 @@ bool PickupSpawnSystem::OnTriggerTouch(Events::TriggerTouch& e) } //personEntered = e.Entity, thingEntered = e.Trigger Events::PlayerHealthPickup ePlayerHealthPickup; - ePlayerHealthPickup.HealthAmount = 30.0f; + ePlayerHealthPickup.HealthAmount = e.Trigger["HealthPickup"]["HealthGain"]; 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"])); + //copy position, healthgain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object) + //we need to copy all values since each value can be different for each healthPickup + m_ETriggerTouchVector.push_back(std::make_tuple( + (glm::vec3)e.Trigger["Transform"]["Position"], + e.Trigger["HealthPickup"]["HealthGain"], + e.Trigger["HealthPickup"]["RespawnTimer"], + e.Trigger["HealthPickup"]["RespawnTimer"])); //delete the healthpickup m_World->DeleteEntity(e.Trigger.ID);