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

@@ -28,7 +28,7 @@ bool canPlaceBuilding(Game *game, BuildingType type, BzTile tileX, BzTile tileY)
BzSpatialGridIter it = bzSpatialGridIter(game->entityGrid, buildArea.x, buildArea.y, buildArea.width, buildArea.height);
while (bzSpatialGridQueryNext(&it)) { ecs_entity_t entity = *(ecs_entity_t *) it.data;
Rectangle bounds;
if (!getEntityHitBox(entity, NULL, &bounds)) continue;
if (!entityGetHitBox(entity, NULL, &bounds)) continue;
if (CheckCollisionRecs(buildArea, bounds))
return false;
@@ -62,6 +62,7 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
.x = sizeX * tileWidth,
.y = sizeY * tileHeight,
};
pos.y += size.y;
HitBox hitbox = {
.x = 0.0f, .y = 0.0f,
.width = size.x,
@@ -73,8 +74,9 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
ecs_set_ptr(ECS, building, HitBox, &hitbox);
ecs_set(ECS, building, Rotation, {0});
HitBox tHitBox = entityTransformHitBox(pos, hitbox);
SpatialGridID gridID = bzSpatialGridInsert(game->entityGrid, &building,
pos.x, pos.y, hitbox.width, hitbox.height);
tHitBox.x, tHitBox.y, tHitBox.width, tHitBox.height);
ecs_set_ptr(ECS, building, SpatialGridID, &gridID);
ecs_set(ECS, building, Owner, {player});
BzTileset *tileset = &game->tileset;