diff options
| author | Eltrac <hi@guhub.cn> | 2025-02-20 16:39:45 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-02-20 16:39:45 +0800 |
| commit | 6fac71363024403c8bc5e92d286153dbe48b389a (patch) | |
| tree | a469c152cdfbb882b323dacd1447c7bcd0bc0124 /objects/Door.lua | |
| parent | 13a208ec28b21279a20438800f5b0acac43eaf1b (diff) | |
refactor: use Body object
- Body defines an object's size and shape
- Body provides a universal function to detect collision
Diffstat (limited to 'objects/Door.lua')
| -rw-r--r-- | objects/Door.lua | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/objects/Door.lua b/objects/Door.lua index 6a8720d..e956bdd 100644 --- a/objects/Door.lua +++ b/objects/Door.lua @@ -9,13 +9,11 @@ local function calculateDoorLocation(obj) if loc == Direction.LEFT or loc == Direction.RIGHT then obj.x = (loc == Direction.LEFT) and (roomX - thickness / 2) or (roomX + roomW - thickness / 2) obj.y = (love.graphics.getHeight() - size) / 2 - obj.width = thickness - obj.height = size + obj.body = Body:new("rectangle", thickness, size) elseif loc == Direction.TOP or loc == Direction.BOTTOM then obj.x = (love.graphics.getWidth() - size) / 2 obj.y = (loc == Direction.TOP) and (roomY - thickness / 2) or (roomY + roomH - thickness / 2) - obj.width = size - obj.height = thickness + obj.body = Body:new("rectangle", size, thickness) end end @@ -30,8 +28,7 @@ function Door:new(location, within, to) x = nil, -- location and size is calculated afterwards y = nil, - width = nil, -- width and height are for graphics, calculated based on size and thickness - height = nil, + body = nil, } setmetatable(obj, Door) |
