1
0
Fork 0
forked from NotAShelf/rogged

map: add is_floor() helper to check walkable tiles

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I7368f74d1cbcf5913e5d8e9331cfa4326a6a6964
This commit is contained in:
raf 2026-04-03 13:59:51 +03:00
commit d3798cc99f
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 5 additions and 5 deletions

View file

@ -13,7 +13,7 @@ void map_init(Map *map) {
map->room_count = 0;
}
int is_floor(Map *map, int x, int y) {
int is_floor(const Map *map, int x, int y) {
if (!in_bounds(x, y, MAP_WIDTH, MAP_HEIGHT))
return 0;
return map->tiles[y][x] == TILE_FLOOR || map->tiles[y][x] == TILE_STAIRS;
@ -62,8 +62,8 @@ static int room_overlaps(Room *rooms, int count, Room *new_room) {
// Add padding to prevent rooms from touching
for (int i = 0; i < count; i++) {
Room *r = &rooms[i];
if (!(new_room->x > r->x + r->w || new_room->x + new_room->w < r->x ||
new_room->y > r->y + r->h || new_room->y + new_room->h < r->y)) {
if (!(new_room->x > r->x + r->w || new_room->x + new_room->w < r->x || new_room->y > r->y + r->h ||
new_room->y + new_room->h < r->y)) {
return 1;
}
}

View file

@ -4,7 +4,7 @@
#include "common.h"
// Check if a tile is walkable floor
int is_floor(Map *map, int x, int y);
int is_floor(const Map *map, int x, int y);
// Get room center coordinates
void get_room_center(Room *room, int *cx, int *cy);
@ -18,4 +18,4 @@ void map_init(Map *map);
// Get a random floor tile position
void get_random_floor_tile(Map *map, int *x, int *y, int attempts);
#endif // MAP_H
#endif // MAP_H