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/Obstacle.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 objects/Obstacle.lua (limited to 'objects/Obstacle.lua') diff --git a/objects/Obstacle.lua b/objects/Obstacle.lua new file mode 100644 index 0000000..0115f36 --- /dev/null +++ b/objects/Obstacle.lua @@ -0,0 +1,16 @@ +Obstacle = {} +Obstacle.__index = Obstacle + +function Obstacle:new(name, location, body) + local obj = { + name = name, + presetLocation = (type(location) == "string" and location) or nil, + x = (type(location) == "table" and location.x) or nil, + y = (type(location) == "table" and location.y) or nil, + body = body or Body:new("rectangle", 10, 10) + } + + setmetatable(obj, Obstacle) + + return obj +end -- cgit v1.2.3