Support for colliders
This commit is contained in:
@@ -7,6 +7,11 @@
|
||||
|
||||
BzTileMap BZ_TILEMAP_INVALID = {.isValid = false};
|
||||
|
||||
|
||||
int16_t bzTileLayerGetTile(BzTileLayer *layer, i32 x, i32 y) {
|
||||
return layer->data[layer->width * y + x];
|
||||
}
|
||||
|
||||
BzTileMap bzTileMapCreate(const BzTileMapDesc *desc) {
|
||||
BzTileMap map = {};
|
||||
i32 tilesetCount = desc->tilesetCount;
|
||||
@@ -97,6 +102,17 @@ BzTileMap bzTileMapCreate(const BzTileMapDesc *desc) {
|
||||
return map;
|
||||
}
|
||||
|
||||
void bzTileMapDestroy(BzTileMap *tilemap) {
|
||||
for (i32 i = 0; i < tilemap->layerCount; i++) {
|
||||
BzTileLayer *layer = tilemap->layers + i;
|
||||
bzFree(layer->data);
|
||||
layer->data = NULL;
|
||||
layer->dataCount = 0;
|
||||
}
|
||||
*tilemap = BZ_TILEMAP_INVALID;
|
||||
}
|
||||
|
||||
|
||||
static void drawLayer(BzTileLayer *layer, BzTileset *tileset) {
|
||||
if (!tileset) return;
|
||||
if (layer->minData == layer->maxData) return;
|
||||
@@ -128,17 +144,23 @@ void bzTileMapDraw(BzTileMap *map) {
|
||||
}
|
||||
}
|
||||
|
||||
void bzTileMapDestroy(BzTileMap *tilemap) {
|
||||
for (i32 i = 0; i < tilemap->layerCount; i++) {
|
||||
BzTileLayer *layer = tilemap->layers + i;
|
||||
bzFree(layer->data);
|
||||
layer->data = NULL;
|
||||
layer->dataCount = 0;
|
||||
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);
|
||||
BzTileCollider collider = bzTilesetGetTileCollider(tileset, tile);
|
||||
if (collider.type != BZ_TILE_COLLIDER_NONE)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
*tilemap = BZ_TILEMAP_INVALID;
|
||||
}
|
||||
|
||||
|
||||
int16_t bzTileLayerGetTile(BzTileLayer *layer, i32 x, i32 y) {
|
||||
return layer->data[layer->width * y + x];
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user