Change collisionMap to boolean value
This commit is contained in:
@@ -37,28 +37,10 @@ bool canPlaceBuilding(BzTileMap *map, BuildingType type, BzTile tileX, BzTile ti
|
||||
if (tile == BUILDINGS_ROAD)
|
||||
return false;
|
||||
}
|
||||
BzTileShape shape = bzTileMapGetCollider(map, x, y);
|
||||
f32 posX = x * map->tileWidth;
|
||||
f32 posY = y * map->tileHeight;
|
||||
shape.x += posX;
|
||||
shape.y += posY;
|
||||
switch (shape.type) {
|
||||
case BZ_TILE_SHAPE_NONE:
|
||||
case BZ_TILE_SHAPE_POINT:
|
||||
break;
|
||||
case BZ_TILE_SHAPE_RECT: {
|
||||
Rectangle shapeRec = {shape.x, shape.y, shape.sizeX, shape.sizeY};
|
||||
if (CheckCollisionRecs(buildArea, shapeRec))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
case BZ_TILE_SHAPE_ELLIPSE: {
|
||||
Vector2 pos = {shape.x, shape.y};
|
||||
f32 radius = (shape.sizeX + shape.sizeY) * 0.5f;
|
||||
if (CheckCollisionCircleRec(pos, radius, buildArea))
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
if (bzTileMapHasCollision(map, posX, posY)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +71,7 @@ ecs_entity_t placeBuilding(BzTileMap *map, BuildingType type, BzTile tileX, BzTi
|
||||
bzTileLayerSetTile(buildingLayer, layerTile, x, y, 1, 1);
|
||||
buildingTile++;
|
||||
|
||||
bzTileMapUpdateColliders(map, x, y, 1, 1);
|
||||
bzTileMapUpdateCollisions(map, x, y, map->tileWidth, map->tileHeight);
|
||||
}
|
||||
buildingTile += buildingTileset->width - sizeX;
|
||||
}
|
||||
|
||||
12
game/main.c
12
game/main.c
@@ -91,7 +91,7 @@ bool init(void *userData) {
|
||||
|
||||
game->map = bzTileMapCreate(&(BzTileMapDesc) {
|
||||
.path="assets/maps/test.tmj",
|
||||
.generateColliderMap=true,
|
||||
.generateCollisionMap=true,
|
||||
.tilesets[0]=game->terrainTileset,
|
||||
.tilesets[1]=game->buildingsTileset,
|
||||
.tilesets[2]=game->entitiesTileset,
|
||||
@@ -140,6 +140,8 @@ bool init(void *userData) {
|
||||
renderDebugPathSystem = renderDebugPath;
|
||||
renderCollidersSystem = renderColliders;
|
||||
|
||||
game->debugDraw.mapColliders = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
void deinit(void *userData) {
|
||||
@@ -151,11 +153,13 @@ void deinit(void *userData) {
|
||||
bzTilesetDestroy(&game->buildingsTileset);
|
||||
bzTilesetDestroy(&game->entitiesTileset);
|
||||
|
||||
Game gameCopy = *game;
|
||||
|
||||
ecs_fini(ECS);
|
||||
ECS = NULL;
|
||||
|
||||
bzObjectPoolDestroy(game->pools.pathData);
|
||||
bzSpatialGridDestroy(game->entityGrid);
|
||||
bzObjectPoolDestroy(gameCopy.pools.pathData);
|
||||
bzSpatialGridDestroy(gameCopy.entityGrid);
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +292,7 @@ void render(float dt, void *userData) {
|
||||
ecs_enable(ECS, renderDebugPathSystem, game->debugDraw.path);
|
||||
ecs_enable(ECS, renderCollidersSystem, game->debugDraw.entityColliders);
|
||||
if (game->debugDraw.mapColliders)
|
||||
bzTileMapDrawColliders(&game->map);
|
||||
bzTileMapDrawCollisions(&game->map);
|
||||
if (game->debugDraw.spatialGrid)
|
||||
bzSpatialGridDrawDebugGrid(game->entityGrid);
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ bool findPath(const PathfindingDesc *desc) {
|
||||
if (y < 0 || y >= map->height ||
|
||||
x < 0 || x >= map->width)
|
||||
continue;
|
||||
if (bzTileMapGetCollider(map, x, y).type != BZ_TILE_SHAPE_NONE)
|
||||
if (bzTileMapHasCollision(map, x, y))
|
||||
continue;
|
||||
Visited *curVisited = &visited[y * map->width + x];
|
||||
if (curVisited->visited)
|
||||
|
||||
Reference in New Issue
Block a user