Added HealthGain to HealthPickup component. Changed PickupSpawnSystem so it copies the values from the old to the new entity.
This commit is contained in:
@@ -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 <tuple>
|
||||
|
||||
@@ -26,8 +22,6 @@ private:
|
||||
EventRelay<PickupSpawnSystem, Events::TriggerTouch> m_ETriggerTouch;
|
||||
bool OnTriggerTouch(Events::TriggerTouch& e);
|
||||
|
||||
std::vector<std::tuple<glm::vec3,double>> m_ETriggerTouchVector;
|
||||
|
||||
|
||||
std::vector<std::tuple<glm::vec3,double,double,double>> m_ETriggerTouchVector;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<HealthPickup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="HealthPickup.xsd">
|
||||
<RespawnTimer>3</RespawnTimer>
|
||||
<HealthGain>30</HealthGain>
|
||||
</HealthPickup>
|
||||
@@ -12,6 +12,9 @@
|
||||
<xs:element name="RespawnTimer" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>The respawn timer for a health pickup</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<xs:element name="HealthGain" type="t:double" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>How much health the player will get when he picks the healthPickup up</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
@@ -238,20 +238,6 @@
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity>
|
||||
<Components>
|
||||
<c:AABB/>
|
||||
<c:HealthPickup/>
|
||||
<c:Model>
|
||||
<Resource>Models/Core/UnitSphere.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="-0.5" Y="1" Z="-8.30000019"/>
|
||||
</c:Transform>
|
||||
<c:Trigger/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
|
||||
@@ -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,6 +23,12 @@ 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());
|
||||
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