From 6fac71363024403c8bc5e92d286153dbe48b389a Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 20 Feb 2025 16:39:45 +0800 Subject: refactor: use Body object - Body defines an object's size and shape - Body provides a universal function to detect collision --- objects/Door.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'objects/Door.lua') 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) -- cgit v1.2.3