Hopefully fixes the "exit under decor" problem for the last time.

This commit is contained in:
Linus_Probert 2018-02-16 09:10:05 +01:00
parent a26c7be122
commit f9443b1468
3 changed files with 19 additions and 7 deletions

View File

@ -121,12 +121,17 @@ local function repack(data)
end
local function check_add_decoration(map, x, y, data)
if tile_occupied(map, x, y) then return end
if tile_occupied(map, x, y) then
return false
end
add_decoration(map, x, y, repack(data))
return true
end
local function check_add_tile(map, x, y, data)
if tile_occupied(map, x, y) then return false end
if tile_occupied(map, x, y) then
return false
end
add_tile(map, x, y, repack(data))
return true
end
@ -232,7 +237,7 @@ local function add_level_exit(map)
while not success do
x = random(14)
y = random(10)
success = check_add_tile(map, x, y, special.level_exit);
success = check_add_tile(map, x, y, special.level_exit)
end
end

View File

@ -24,7 +24,6 @@ typedef struct MapTile_t {
typedef struct Room_t {
MapTile* tiles[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
MapTile* secondary_tiles[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
MapTile* decorations[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
} Room;

View File

@ -153,10 +153,13 @@ int l_tile_occupied(lua_State *L)
{
Map *map;
Room *room;
MapTile *tile;
MapTile *tile, *decor;
Position *rPos;
int x, y;
bool response = false;
tile = NULL;
decor = NULL;
map = luaL_checkmap(L, 1);
x = (int) luaL_checkinteger(L, 2);
@ -164,9 +167,14 @@ int l_tile_occupied(lua_State *L)
rPos = &map->currentRoom;
room = map->rooms[rPos->x][rPos->y];
tile = room->tiles[x][y];
lua_pushboolean(L, tile->collider || tile->levelExit);
tile = room->tiles[x][y];
decor = room->decorations[x][y];
response = response || (tile && (tile->collider || tile->levelExit));
response = response || (decor && (decor->collider || decor->levelExit));
lua_pushboolean(L, response);
return 1;
}