Add health

This commit is contained in:
2024-02-07 16:12:45 +01:00
parent eb768fa968
commit d6466b8f55
7 changed files with 72 additions and 1 deletions

View File

@@ -270,9 +270,45 @@ void updateBuildingRecruitment(ecs_iter_t *it) {
}
}
void renderHealth(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
HitBox *hitbox = ecs_field(it, HitBox, 2);
Health *health = ecs_field(it, Health, 3);
for (i32 i = 0; i < it->count; i++) {
HitBox hb = entityTransformHitBox(pos[i], hitbox[i]);
const f32 HP_WIDTH = 10.0f;
const f32 HP_HEIGHT = 1.8f;
const f32 HP_OFFSET = 2.0f;
const Color BG_COLOR = {0, 0, 0, 60};
const Color HP_COLOR = {255, 0, 0, 220};
const f32 PADDING = 0.15f;
Vector2 hpPos = {
hb.x + (hb.width - HP_WIDTH) * 0.5f,
hb.y - HP_OFFSET - HP_HEIGHT
};
Vector2 size = {
HP_WIDTH, HP_HEIGHT
};
f32 hpPercent = health[i].hp / health[i].startHP;
Vector2 hpSize = {
HP_WIDTH * hpPercent - PADDING * 2.0f,
HP_HEIGHT - PADDING * 2.0f
};
DrawRectangleV(hpPos, size, BG_COLOR);
hpPos.x += PADDING;
hpPos.y += PADDING;
DrawRectangleV(hpPos, hpSize, HP_COLOR);
}
}
void renderColliders(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
HitBox *hitbox = ecs_field(it, HitBox , 2);
HitBox *hitbox = ecs_field(it, HitBox, 2);
for (i32 i = 0; i < it->count; i++) {
HitBox hb = entityTransformHitBox(pos[i], hitbox[i]);

View File

@@ -113,6 +113,7 @@ void setupSystems() {
ECS_SYSTEM(ECS, updateAnimation, EcsOnUpdate, Animation, TextureRegion);
ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, HitBox, Rotation);
ECS_SYSTEM(ECS, renderHealth, EcsOnUpdate, Position, HitBox, Health);
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox);

View File

@@ -147,6 +147,13 @@ void entityFollowPath(ecs_iter_t *it);
*/
void updateBuildingRecruitment(ecs_iter_t *it);
/*
* 1: Position
* 2: HitBox
* 3: Health
*/
void renderHealth(ecs_iter_t *it);
/*
* 1: Position
* 2: HitBox