0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 10:13:42 +00:00
SDL_Minigame/include/HealthComponent.h
2024-01-22 17:54:36 -06:00

65 lines
1.2 KiB
C++

#include "Components.h"
class HealthComponent : public Component {
public:
HealthComponent(int health, Manager* manager, bool player) : health(health), manager(manager), player(player) {}
~HealthComponent() {}
void getDamage() {
this->health--;
}
int getHealth() {
return this->health;
}
void init() override
{
createAllHearts();
}
void createAllHearts() {
int x; //starting position for first health icon
if(player) {
x = 10;
} else {
x = 750;
}
for(int i = 0; i < health; i++) {
//checks for player side
if(player) {
createHeartComponents(x);
x += 50;
continue;
}
createHeartComponents(x);
x -= 50;
}
}
void createHeartComponents(int x) {
auto& heart(manager->addEntity());
heart.addComponent<TransformComponent>(x,5,1);
heart.addComponent<SpriteComponent>("assets/chicken_neutral_knight.png");
heart.addGroup(Game::HEARTS);
}
private:
int health;
Manager* manager;
bool player; //true if player1 / false if player2
};