-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolliders.lua
More file actions
32 lines (26 loc) · 964 Bytes
/
colliders.lua
File metadata and controls
32 lines (26 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local scandir = _Require_relative(..., 'scandir')
local Collider = _Require_relative(..., 'colliders.Collider')
-- Two kinds of shapes:
-- circles and polygons
local Colliders = {}
function Colliders:Create_Definition(name, object)
--Check that the object implements new
assert(object.new, "\tnew is null for shape: ".. name..'\n Make sure to :extend() it')
self[name] = object
end
local function load_colliders(cwd)
local shape_files = scandir('colliders')
for _, filename in ipairs(shape_files) do
local name = filename:sub(1,filename:len()-4)
local c = _Require_relative(cwd, 'colliders.'..name)
if type(c) == 'table' and c:implements(Collider) then
-- Add to shapes
Colliders:Create_Definition(name, c)
else
Colliders[name] = false
end
end
end
load_colliders(...)
-- Shapes: edge, aabb, ellipse, regular poly, convex poly, concave poly
return Colliders