Files
axyz/src/Game/Systems/HealthHUDSystem.cpp
T

47 lines
1.8 KiB
C++

#include "Game/Systems/HealthHUDSystem.h"
void HealthHUDSystem::Update(double dt)
{
auto healthHUDs = m_World->GetComponents("HealthHUD");
if (healthHUDs == nullptr) {
return;
}
for (auto& healthHUDComponent : *healthHUDs) {
EntityWrapper entity = EntityWrapper(m_World, healthHUDComponent.EntityID);
EntityWrapper entityIDParent = entity;
while (entityIDParent.Parent().Valid()) {
entityIDParent = entityIDParent.Parent();
if (entityIDParent.HasComponent("Health")) {
break;
}
}
if (entityIDParent.HasComponent("Health")) {
if (entity.HasComponent("Text")) {
Field<double> health = entityIDParent["Health"]["Health"];
Field<double> maxHealth = entityIDParent["Health"]["Health"];
std::string s = "";
s = s + std::to_string((int)health);
s = s + "/";
s = s + std::to_string((int)maxHealth);
float healthPercentage = health/maxHealth;
//(Field<glm::vec4>)entity["Text"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Text"]["Color"]).a);
entity["Text"]["Content"] = s;
}
if(entity.HasComponent("Fill")) {
Field<double> health = entityIDParent["Health"]["Health"];
Field<double> maxHealth = entityIDParent["Health"]["Health"];
float healthPercentage = health/maxHealth;
entity["Fill"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, glm::vec4(entity["Fill"]["Color"]).a);
entity["Fill"]["Percentage"] = (double)healthPercentage;
}
}
}
}