EntityWrapper to uniquely identify entities and make using them a little easier

This commit is contained in:
2016-01-14 15:43:19 +01:00
parent 28392def79
commit d34470256b
20 changed files with 106 additions and 72 deletions
+7 -7
View File
@@ -10,24 +10,24 @@ HealthSystem::HealthSystem(EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerHealthPickup, &HealthSystem::OnPlayerHealthPickup);
}
void HealthSystem::UpdateComponent(World *world, ComponentWrapper &health, double dt)
void HealthSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
//if entityID of health is 9 then the players ID is also 9 (player,health are connected to the same entity)
ComponentWrapper player = world->GetComponent(health.EntityID, "Player");
double maxHealth = (double)health["MaxHealth"];
ComponentWrapper player = world->GetComponent(component.EntityID, "Player");
double maxHealth = (double)component["MaxHealth"];
//process the DeltaHealthVector and change the entitys health accordingly
for (size_t i = m_DeltaHealthVector.size(); i > 0; i--)
{
auto deltaHP = m_DeltaHealthVector[i - 1];
//if we have a healthchange for the current player and health is greater than 0, then apply it
if (std::get<0>(deltaHP) == player.EntityID && (double)health["Health"] > 0.0f) {
if (std::get<0>(deltaHP) == player.EntityID && (double)component["Health"] > 0.0f) {
//get the deltaHP value from the tuple and make sure you dont get more than maxHealth
double newHealth = std::min((double)health["Health"] + (double)std::get<1>(deltaHP), maxHealth);
health["Health"] = newHealth;
double newHealth = std::min((double)component["Health"] + (double)std::get<1>(deltaHP), maxHealth);
component["Health"] = newHealth;
m_DeltaHealthVector.erase(m_DeltaHealthVector.begin() + i - 1);
//check if health is <= 0
if ((double)health["Health"] <= 0.0f) {
if ((double)component["Health"] <= 0.0f) {
//publish death event
Events::PlayerDeath e;
e.PlayerID = player.EntityID;
+3 -4
View File
@@ -1,7 +1,6 @@
#include "RaptorCopterSystem.h"
void PlayerMovementSystem::UpdateComponent(World* world, ComponentWrapper& player, double dt)
void PlayerMovementSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
}
ComponentWrapper& transform = world->GetComponent(component.EntityID);
}
+13 -13
View File
@@ -1,25 +1,25 @@
#include "PlayerSystem.h"
void PlayerSystem::UpdateComponent(World * world, ComponentWrapper & player, double dt)
void PlayerSystem::UpdateComponent(World* world, EntityWrapper& entity, ComponentWrapper& component, double dt)
{
player["Velocity"] = glm::vec3(0.f, 0.f, 0.f);
if ((bool&)player["Forward"] == true) {
((glm::vec3&)player["Velocity"]).z = m_Speed * float(dt) * -1;
component["Velocity"] = glm::vec3(0.f, 0.f, 0.f);
if ((bool&)component["Forward"] == true) {
((glm::vec3&)component["Velocity"]).z = m_Speed * float(dt) * -1;
}
if ((bool&)player["Left"] == true) {
((glm::vec3&)player["Velocity"]).x = m_Speed * float(dt) * -1;
if ((bool&)component["Left"] == true) {
((glm::vec3&)component["Velocity"]).x = m_Speed * float(dt) * -1;
}
if ((bool&)player["Back"] == true) {
((glm::vec3&)player["Velocity"]).z = m_Speed * float(dt);
if ((bool&)component["Back"] == true) {
((glm::vec3&)component["Velocity"]).z = m_Speed * float(dt);
}
if ((bool&)player["Right"] == true) {
((glm::vec3&)player["Velocity"]).x = m_Speed * float(dt);
if ((bool&)component["Right"] == true) {
((glm::vec3&)component["Velocity"]).x = m_Speed * float(dt);
}
if ((glm::vec3)player["Velocity"] != glm::vec3(0.f)) {
ComponentWrapper& transform = world->GetComponent(player.EntityID, "Transform");
(glm::vec3&)transform["Position"] += (glm::vec3)player["Velocity"];
if ((glm::vec3)component["Velocity"] != glm::vec3(0.f)) {
ComponentWrapper& transform = world->GetComponent(component.EntityID, "Transform");
(glm::vec3&)transform["Position"] += (glm::vec3)component["Velocity"];
}
}