diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-09 09:56:53 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-09 09:56:53 +0800 |
| commit | c4b1a488b3c995dff5597f1dc4e725232682c231 (patch) | |
| tree | b5603f6e55fa0de70bdc1ad9c0884f3baef26830 /objects/room.lua | |
| parent | a835310b5e6906b5f393b01becd4c2a2911e4e47 (diff) | |
feat: remove door back when entering a new map
also ensure randomness when connecting two rooms
Diffstat (limited to 'objects/room.lua')
| -rw-r--r-- | objects/room.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/objects/room.lua b/objects/room.lua index 23ab73e..7982e9c 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -140,6 +140,14 @@ function Room:addDoor(door) table.insert(self.doors, door) end +function Room:removeDoor(door) + for i, item in ipairs(self.doors) do + if item == door then + table.remove(self.doors, i) + end + end +end + function Room:connect(anotherRoom, way) if self:isDoorFull() or anotherRoom:isDoorFull() then return false @@ -156,6 +164,7 @@ function Room:connect(anotherRoom, way) local dd1 = self:getDoorlessDirections() local dd2 = anotherRoom:getDoorlessDirections() + utils.shuffle(dd1) for _, dir1 in ipairs(dd1) do local dir2 = OppositeDirection[dir1] if (utils.contains(dd2, dir2)) then |
