Add 8 layers to collisions
This commit is contained in:
@@ -78,7 +78,7 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
|
||||
region.rec.height *= sizeY;
|
||||
ecs_set_ptr(ECS, building, TextureRegion, ®ion);
|
||||
|
||||
bzTileMapSetCollisions(&game->map, true, posX, posY, sizeX, sizeY);
|
||||
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
||||
|
||||
switch (type) {
|
||||
case BUILDING_KEEP:
|
||||
|
||||
9
game/constants.h
Normal file
9
game/constants.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef PIXELDEFENSE_CONSTANTS_H
|
||||
#define PIXELDEFENSE_CONSTANTS_H
|
||||
|
||||
enum {
|
||||
COLL_LAYER_TERRAIN = 0,
|
||||
COLL_LAYER_BUILDINGS = 1,
|
||||
};
|
||||
|
||||
#endif //PIXELDEFENSE_CONSTANTS_H
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <breeze.h>
|
||||
#include <flecs.h>
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
typedef enum GameScreen {
|
||||
SCREEN_GAME,
|
||||
SCREEN_PAUSE_MENU,
|
||||
|
||||
@@ -95,7 +95,7 @@ void unloadMap(Game *game) {
|
||||
void loadMap(Game *game, const char *path) {
|
||||
game->map = bzTileMapCreate(&(BzTileMapDesc) {
|
||||
.path=path,
|
||||
.generateCollisionMap=true,
|
||||
.collisionMap=true,
|
||||
.tilesets[0]=game->tileset,
|
||||
|
||||
.layers[LAYER_TERRAIN]=(BzTileLayerDesc) {"terrain", .renderer=terrainRender, .applyColliders=true},
|
||||
@@ -123,6 +123,8 @@ void loadMap(Game *game, const char *path) {
|
||||
game->camera.rotation = 0.0f;
|
||||
game->camera.zoom = 3.0f;
|
||||
|
||||
bzTileMapAddLayerCollisions(&game->map, LAYER_TERRAIN, COLL_LAYER_TERRAIN);
|
||||
|
||||
bzTileMapOverrideLayer(&game->map, LAYER_TREES, initTreesLayer);
|
||||
bzTileMapOverrideLayer(&game->map, LAYER_TREES2, initTreesLayer);
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ bool pathfindAStar(const PathfindingDesc *desc) {
|
||||
x < 0 || x >= map->width)
|
||||
continue;
|
||||
// not walkable
|
||||
if (bzTileMapHasCollision(map, x, y))
|
||||
if (bzTileMapHasAnyCollision(map, x, y))
|
||||
continue;
|
||||
PathNodeRecord *curRecord = &closedSet[y * map->width + x];
|
||||
if (curRecord->visited)
|
||||
|
||||
@@ -412,7 +412,7 @@ void addEntityToInspected(ecs_entity_t entity, Game *game) {
|
||||
}
|
||||
|
||||
static bool isUnitObstructed(f32 x, f32 y, BzTileMap *map) {
|
||||
return bzTileMapHasCollision(map, x / map->tileWidth, y / map->tileHeight);
|
||||
return bzTileMapHasAnyCollision(map, x / map->tileWidth, y / map->tileHeight);
|
||||
}
|
||||
|
||||
static bool canPlaceUnit(Vector2 pos, f32 space, BzTileMap *map) {
|
||||
|
||||
@@ -81,7 +81,7 @@ 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);
|
||||
bzTileMapSetCollisions(&game->map, false, COLL_LAYER_BUILDINGS, pos.x, pos.y, size.x, size.y);
|
||||
})
|
||||
ECS_MOVE(Building, dst, src, {
|
||||
*dst = *src;
|
||||
|
||||
Reference in New Issue
Block a user