Fix hitboxes for entities
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user