Loading...
Searching...
No Matches
HealthSystem.h
Go to the documentation of this file.
1//
2// Created by Dave Smith on 3/11/25.
3//
4
5#ifndef HEALTHSYSTEM_H
6#define HEALTHSYSTEM_H
7
8#pragma once
9
10#include <iostream>
11
12#include "Core/ECSManager.h"
14
15namespace ml
16{
22 {
23 public:
24 void applyDamage(EventManagerECS &eventManager, ECSManager &ecs, Entity entity, int damage)
25 {
26 if (ecs.healths.find(entity) != ecs.healths.end())
27 {
28 eventManager.pushEvent([&, entity, damage]() {
29 ecs.healths[entity].health -= damage;
30 std::cout << "Entity " << entity << " took " << damage
31 << " damage! Health: " << ecs.healths[entity].health << std::endl;
32
33 if (ecs.healths[entity].health <= 0)
34 {
35 std::cout << "Entity " << entity << " has died!\n";
36 ecs.healths.erase(entity);
37 ecs.positions.erase(entity);
38 ecs.velocities.erase(entity);
39 }
40 });
41 }
42 }
43 };
44}
45
46
47#endif // HEALTHSYSTEM_H
ECSManager.
Definition ECSManager.h:23
std::unordered_map< Entity, PositionComponent > positions
Definition ECSManager.h:25
std::unordered_map< Entity, HealthComponent > healths
Definition ECSManager.h:27
std::unordered_map< Entity, VelocityComponent > velocities
Definition ECSManager.h:26
EventManagerECS.
void pushEvent(const std::function< void()> &event)
HealthSystem.
void applyDamage(EventManagerECS &eventManager, ECSManager &ecs, Entity entity, int damage)
Definition Component.h:18
int Entity
Definition ECSManager.h:16