summaryrefslogtreecommitdiff
path: root/objects/room.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-02-18 20:24:41 +0800
committerEltrac <hi@guhub.cn>2025-02-18 20:24:41 +0800
commit423cfe133ae8a8f9d7a87b2c4d151af3fd7aa7fc (patch)
tree10c4d8eedcc65155b0f234d6d74be6663bcf5bb0 /objects/room.lua
parent875cc3e70c11e589c548775c3208659f50daf7df (diff)
feat: entering new rooms
- door connects two rooms - detects if player enters a door, if so, then switch room and update player location
Diffstat (limited to 'objects/room.lua')
-rw-r--r--objects/room.lua33
1 files changed, 23 insertions, 10 deletions
diff --git a/objects/room.lua b/objects/room.lua
index 2fc09e7..63360e1 100644
--- a/objects/room.lua
+++ b/objects/room.lua
@@ -7,23 +7,21 @@ local RoomType = {
LOOT = 3
}
-Direction = {
- LEFT = 1, RIGHT = 2, TOP = 3, BOTTOM = 4
-}
-
-function Room:new()
+function Room:new(type, w, h)
local obj = {
- width = 0.85, height = 0.8,
+ type = type or RoomType.INITIAL,
+ width = w or 0.85,
+ height = h or 0.8,
doors = {},
- borders = {},
enemies = {},
isCleared = false,
- type = RoomType.INITIAL
+
+ -- borders are automatically caculated afterwards
+ borders = {},
}
setmetatable(obj, Room)
- table.insert(obj.doors, Door:new(math.random(1,4), obj))
obj.borders = obj:getBorders()
return obj
@@ -53,7 +51,11 @@ function Room:getBorders()
return { left, right, top, bottom }
end
-function Room:switch(to)
+function Room:addDoor(door)
+ table.insert(self.doors, door)
+end
+
+function Room.switch(to)
if type(to) == "table" then
G.currentRoom = to
elseif type(to) == "number" then
@@ -61,4 +63,15 @@ function Room:switch(to)
end
end
+function Room.generate()
+ local room1 = Room:new()
+ local room2 = Room:new()
+ Door.connect(room1, room2, "lr")
+
+ local room3 = Room:new()
+ Door.connect(room3, room2, "tb")
+
+ return room1
+end
+
return Room