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.

This commit is contained in:
verysecrethero
2016-02-05 15:15:04 +01:00
parent 6a23a987b3
commit fe6fd0bbe3
13 changed files with 368 additions and 35 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Events
struct PickupSpawned : Event
{
EntityID PickupID;
EntityWrapper Spawner;
EntityWrapper Pickup;
};
}
-19
View File
@@ -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
+16
View File
@@ -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 <tuple>
class PickupSpawnSystem : public ImpureSystem
{
public:
PickupSpawnSystem(World* world, EventBroker* eventBroker);
virtual void Update(double dt) override;
private:
EventRelay<PickupSpawnSystem, Events::TriggerTouch> m_ETriggerTouch;
bool OnTriggerTouch(Events::TriggerTouch& e);
std::vector<std::tuple<glm::vec3,double>> m_ETriggerTouchVector;
};
#endif
+1 -1
View File
@@ -29,5 +29,5 @@
<xs:include schemaLocation="Components/Fill.xsd"/>
<xs:include schemaLocation="Components/Lifetime.xsd"/>
<xs:include schemaLocation="Components/HiddenForLocalPlayer.xsd"/>
<xs:include schemaLocation="Components/PickupSpawn.xsd"/>
<xs:include schemaLocation="Components/HealthPickup.xsd"/>
</xs:schema>
@@ -0,0 +1,4 @@
<?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>
</HealthPickup>
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="HealthPickup">
<xs:annotation>
<xs:documentation>A Health Pickup</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:all>
<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:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<PlayerSpawn xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PickupSpawn.xsd"/>
@@ -1,11 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="PickupSpawn">
<xs:annotation>
<xs:documentation>Combined with a Spawner, defines a spawn point for a pickup</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
+1 -1
View File
@@ -5,7 +5,7 @@
<c:AABB/>
<c:CapturePoint/>
<c:Model>
<Resource>C:\Users\123456\Workspace\TacticalZ\assets\Models\Core\UnitSphere.mesh</Resource>
<Resource>Models/Core/UnitSphere.mesh</Resource>
</c:Model>
<c:Team/>
<c:Transform/>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:AABB/>
<c:HealthPickup/>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="60" Y="1" Z="80"/>
</c:Transform>
<c:Trigger/>
</Components>
<Children/>
</Entity>
@@ -0,0 +1,257 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity name="Scenemesh">
<Components>
<c:Model>
<Resource>Models\MapVersion1.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="DirectionalLight">
<Components>
<c:DirectionalLight>
<Intensity>2</Intensity>
</c:DirectionalLight>
<c:Model>
<Resource>Models/DirectionalLightWidget.mesh</Resource>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="0" Y="61.9050903" Z="0"/>
<Scale X="50" Y="50" Z="50"/>
<Orientation X="4.42700005" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="PointLight">
<Components>
<c:PointLight>
<Radius>8</Radius>
<Intensity>2.7999999523162842</Intensity>
</c:PointLight>
<c:Transform>
<Position X="0.370978802" Y="1.88588905" Z="-0.55370003"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="PointLight">
<Components>
<c:PointLight>
<Radius>8</Radius>
<Intensity>2.7999999523162842</Intensity>
</c:PointLight>
<c:Transform>
<Position X="38.0347443" Y="1.88588905" Z="62.7340622"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-0.904668212" Y="0" Z="8.48177528"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-4.61666441" Y="0" Z="-8.51156044"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="-7.56803513" Y="-0.0658408776" Z="0.59418112"/>
<Scale X="1.20000005" Y="0.900000036" Z="1.30000007"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="10.460474" Y="0" Z="-3.92580295"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:AABB/>
<c:Collidable/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="1.09146011" Y="-0.315138876" Z="-0.333906144"/>
<Scale X="150" Y="1" Z="180"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="BluSpawn">
<Components>
<c:PlayerSpawn/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Visible>false</Visible>
</c:Model>
<c:Spawner>
<EntityFile>Schema/Entities/Player.xml</EntityFile>
</c:Spawner>
<c:Team>
<Team>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="57.7363472" Y="1.18853188" Z="79.5"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:SpawnPoint/>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:SpawnPoint/>
<c:Transform>
<Position X="-2.05988312" Y="0" Z="2.79573512"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="1.85022807" Y="0" Z="-2.08909845"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="2.98651481" Y="0" Z="-4.67667246"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="-5.16323137" Y="0" Z="3.62892342"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RedSpawn">
<Components>
<c:PlayerSpawn/>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Visible>false</Visible>
</c:Model>
<c:Spawner>
<EntityFile>Schema/Entities/Player.xml</EntityFile>
</c:Spawner>
<c:Team>
<Team>
<Red/>
</Team>
</c:Team>
<c:Transform>
<Position X="-60.2567062" Y="1.60000002" Z="-78.1000061"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:SpawnPoint/>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0" Y="0" Z="2.24403"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="2.20245028" Y="0" Z="-1.97843659"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Transform>
<Position X="4.79769945" Y="0" Z="-5.2088728"/>
</c:Transform>
</Components>
<Children/>
</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>
+2
View File
@@ -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<WeaponSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
+50
View File
@@ -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<EntityFile>("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;
}