Soft fail, when checking for collisions outside map bounds
This commit is contained in:
@@ -488,11 +488,15 @@ void bzTileMapClearCollisionLayer(BzTileMap *map, i32 layer) {
|
||||
}
|
||||
bool bzTileMapHasAnyCollision(BzTileMap *map, i32 x, i32 y) {
|
||||
if (!map->collisionMap) return false;
|
||||
if (x < 0 || x >= map->width || y < 0 || y >= map->height)
|
||||
return false;
|
||||
i32 idx = y * map->width + x;
|
||||
return map->collisionMap[idx] != 0;
|
||||
}
|
||||
bool bzTileMapHasCollision(BzTileMap *map, i32 layer, i32 x, i32 y) {
|
||||
BZ_ASSERT(layer >= 0 && layer < 8);
|
||||
if (x < 0 || x >= map->width || y < 0 || y >= map->height)
|
||||
return false;
|
||||
if (!map->collisionMap) return false;
|
||||
i32 idx = y * map->width + x;
|
||||
return (map->collisionMap[idx] & (1 << layer)) != 0;
|
||||
@@ -502,9 +506,8 @@ void bzTileMapSetCollisions(BzTileMap *map, bool collision, i32 layer, i32 start
|
||||
i32 endY = startY + sizeY;
|
||||
BZ_ASSERT(layer >= 0 && layer < 8);
|
||||
BZ_ASSERT(map->collisionMap);
|
||||
BZ_ASSERT(startX >= 0 && endX <= map->width &&
|
||||
startY >= 0 && endY <= map->height);
|
||||
|
||||
if (startX < 0 || endX >= map->width || startY < 0 || endY >= map->height)
|
||||
return;
|
||||
for (i32 y = startY; y < endY; y++) {
|
||||
for (i32 x = startX; x < endX; x++) {
|
||||
i32 idxOffset = y * map->width + x;
|
||||
|
||||
Reference in New Issue
Block a user