Make collider retrieving more permissive

This commit is contained in:
2023-11-09 09:49:14 +01:00
parent ced7aa2ea5
commit 6cc3ce9750
3 changed files with 22 additions and 23 deletions

View File

@@ -276,28 +276,10 @@ void bzTileMapDrawColliders(BzTileMap *map) {
}
}
bool bzTileMapCanPlace(BzTileMap *map, i32 tileX, i32 tileY, i32 sizeX, i32 sizeY) {
for (i32 y = tileY; y < tileY + sizeY; y++) {
for (i32 x = tileX; x < tileX + sizeX; x++) {
for (i32 i = 0; i < map->layerCount; i++) {
BzTileLayer *layer = map->layers + i;
if (layer->tilesetIdx == -1) continue;
BzTileset *tileset = map->tilesets + layer->tilesetIdx;
i16 tile = bzTileLayerGetTile(layer, x, y);
BzTileShape collider = bzTilesetGetTileCollider(tileset, tile);
if (collider.type != BZ_TILE_SHAPE_NONE)
return false;
}
}
}
return true;
}
BzTileCollider bzTileMapGetCollider(BzTileMap *map, i32 x, i32 y) {
i32 idx = y * map->width + x;
BZ_ASSERT(idx < 0 && idx < map->collidersCount);
if (idx < 0 || idx >= map->collidersCount) {
return (BzTileCollider) {{BZ_TILE_SHAPE_NONE}};
}
return map->colliderMap[idx];
}

View File

@@ -95,7 +95,6 @@ void bzTileMapDestroy(BzTileMap *tilemap);
void bzTileMapDraw(BzTileMap *map);
void bzTileMapDrawColliders(BzTileMap *map);
bool bzTileMapCanPlace(BzTileMap *map, i32 tileX, i32 tileY, i32 sizeX, i32 sizeY);
BzTileCollider bzTileMapGetCollider(BzTileMap *map, i32 x, i32 y);