From c4b1a488b3c995dff5597f1dc4e725232682c231 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sun, 9 Mar 2025 09:56:53 +0800 Subject: feat: remove door back when entering a new map also ensure randomness when connecting two rooms --- objects/room.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'objects/room.lua') 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 -- cgit v1.2.3