Properly handle map collisions when placing/destroying buildings

This commit is contained in:
2024-01-08 15:27:58 +01:00
parent c08fca9670
commit 88cbfe4a37
8 changed files with 56 additions and 7 deletions

View File

@@ -75,7 +75,17 @@ ECS_DTOR(Arms, arms, {
})
ECS_MOVE(Arms, dst, src, {
*dst = *src;
});
})
ECS_DTOR(Building, building, {
Vec2i pos = building->pos;
Vec2i size = building->size;
Game *game = ecs_singleton_get_mut(ECS, Game);
bzTileMapSetCollisions(&game->map, false, pos.x, pos.y, size.x, size.y);
})
ECS_MOVE(Building, dst, src, {
*dst = *src;
})
void setupSystems() {
ecs_set_hooks(ECS, SpatialGridID, {
@@ -90,6 +100,10 @@ void setupSystems() {
.dtor = ecs_dtor(Arms),
.move_dtor = ecs_move(Arms)
});
ecs_set_hooks(ECS, Building, {
.dtor = ecs_dtor(Building),
.move_dtor = ecs_move(Building)
});
ECS_OBSERVER(ECS, entityPathRemove, EcsOnRemove, Path);