Fix hitboxes for entities

This commit is contained in:
2024-01-28 14:09:27 +01:00
parent a61768e912
commit 5d96a02284
11 changed files with 67 additions and 49 deletions

View File

@@ -309,22 +309,19 @@ void drawPlayerInputUIGround() {
for (i32 i = 0; i < it.count; i++) {
ecs_entity_t entity = it.entities[i];
f32 radius = BZ_MAX(hitbox[i].width, hitbox[i].height);
Position center = entityGetCenter(pos[i], hitbox[i]);
radius *= 0.8f;
const f32 lineThickness = 1.0f;
if (ecs_has(ECS, entity, Building)) {
const f32 padding = 2.0f;
Rectangle bounds = {
pos[i].x + hitbox[i].x - padding,
pos[i].y - hitbox[i].y - padding,
pos[i].y - hitbox[i].height - padding,
hitbox[i].width + padding * 2,
hitbox[i].height + padding * 2,
};
DrawRectangleLinesEx(bounds, lineThickness, GREEN);
} else {
Position center = {
pos[i].x + hitbox[i].x + hitbox[i].width * 0.5f,
pos[i].y + hitbox[i].y + hitbox[i].height * 0.5f,
};
DrawRing(center, radius, radius + lineThickness, 0, 360, 12, GREEN);
}
}
@@ -372,7 +369,7 @@ ecs_entity_t queryEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t
if (!ecs_has_id(ECS, entity, tag)) continue;
Vector2 pos;
Rectangle hitbox;
if (!getEntityHitBox(entity, &pos, &hitbox)) continue;
if (!entityGetHitBox(entity, &pos, &hitbox)) continue;
if (!CheckCollisionPointRec(point, hitbox)) continue;
@@ -410,7 +407,7 @@ void selectUnits(BzSpatialGrid *entityGrid, Rectangle area, Player player) {
}
if (!ecs_has_id(ECS, entity, ecs_id(Unit))) continue;
Rectangle hitbox;
if (!getEntityHitBox(entity, NULL, &hitbox)) continue;
if (!entityGetHitBox(entity, NULL, &hitbox)) continue;
if (!CheckCollisionRecs(area, hitbox)) continue;
ecs_add(ECS, entity, Selected);