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/Obstacle.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/Obstacle.lua')
| -rw-r--r-- | objects/Obstacle.lua | 16 |
1 files changed, 16 insertions, 0 deletions
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 |
