Added HealthGain to HealthPickup component. Changed PickupSpawnSystem so it copies the values from the old to the new entity.
This commit is contained in:
@@ -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<EntityFile>("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);
|
||||
|
||||
Reference in New Issue
Block a user