summaryrefslogtreecommitdiff
path: root/objects/Door.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/Door.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/Door.lua')
-rw-r--r--objects/Door.lua27
1 files changed, 22 insertions, 5 deletions
diff --git a/objects/Door.lua b/objects/Door.lua
index 0be3b34..d667406 100644
--- a/objects/Door.lua
+++ b/objects/Door.lua
@@ -2,8 +2,8 @@ Door = {}
Door.__index = Door
local function calculateDoorLocation(obj)
- local roomX, roomY = obj.room:getX(), obj.room:getY()
- local roomW, roomH = obj.room:getWidth(), obj.room:getHeight()
+ local roomX, roomY = obj.within:getX(), obj.within:getY()
+ local roomW, roomH = obj.within:getWidth(), obj.within:getHeight()
local loc, size, thickness = obj.location, obj.size, obj.thickness
if loc == Direction.LEFT or loc == Direction.RIGHT then
@@ -19,13 +19,14 @@ local function calculateDoorLocation(obj)
end
end
-function Door:new(location, room)
+function Door:new(location, within, to)
local obj = {
- to = nil,
location = location,
size = config.graphics.doorSize,
thickness = config.graphics.doorThickness,
- room = room,
+
+ within = within,
+ to = to,
x = nil, -- location and size is calculated afterwards
y = nil,
@@ -44,4 +45,20 @@ function Door:setTo(room)
self.to = room
end
+function Door.connect(room1, room2, way)
+ local door1, door2
+ if way == "lr" then
+ door1 = Door:new(Direction.LEFT, room1, room2)
+ door2 = Door:new(Direction.RIGHT, room2, room1)
+ room1:addDoor(door1)
+ room2:addDoor(door2)
+ elseif way == "tb" then
+ door1 = Door:new(Direction.TOP, room1, room2)
+ door2 = Door:new(Direction.BOTTOM, room2, room1)
+ room1:addDoor(door1)
+ room2:addDoor(door2)
+ end
+ return door1, door2
+end
+
return Door