From 423cfe133ae8a8f9d7a87b2c4d151af3fd7aa7fc Mon Sep 17 00:00:00 2001 From: Eltrac Date: Tue, 18 Feb 2025 20:24:41 +0800 Subject: feat: entering new rooms - door connects two rooms - detects if player enters a door, if so, then switch room and update player location --- objects/room.lua | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'objects/room.lua') 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 -- cgit v1.2.3