initial commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
Class = {}
|
||||
Class.__index = Class
|
||||
|
||||
function Class:new(tbl)
|
||||
tbl = tbl or {}
|
||||
setmetatable(tbl, { __index = self })
|
||||
end
|
||||
@@ -0,0 +1,61 @@
|
||||
collision = {}
|
||||
collision.colliders = {}
|
||||
|
||||
collision.debug = false
|
||||
|
||||
function collision.draw()
|
||||
for _, v in pairs(collision.colliders) do
|
||||
gfx.rect(v.x, v.y, v.w, v.h, gfx.COLOR_BLUE)
|
||||
end
|
||||
end
|
||||
|
||||
function collision.add(tbl)
|
||||
table.insert(collision.colliders, tbl)
|
||||
end
|
||||
|
||||
function collision.remove(index)
|
||||
table.remove(collision.colliders, index)
|
||||
end
|
||||
|
||||
function collision.move(aabb, dx, dy)
|
||||
local normal = { x = 0, y = 0 }
|
||||
if aabb.normal ~= nil then
|
||||
aabb.normal = normal
|
||||
end
|
||||
|
||||
-- move x
|
||||
aabb.x = aabb.x + dx
|
||||
|
||||
for _, v in pairs(collision.colliders) do
|
||||
if aabb ~= v and collision.aabb_check(aabb, v) then
|
||||
if dx > 0 then
|
||||
aabb.x = v.x - aabb.w
|
||||
normal.x = -1
|
||||
elseif dx < 0 then
|
||||
aabb.x = v.x + v.w
|
||||
normal.x = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- move y
|
||||
aabb.y = aabb.y + dy
|
||||
|
||||
for _, v in pairs(collision.colliders) do
|
||||
if aabb ~= v and collision.aabb_check(aabb, v) then
|
||||
if dy > 0 then
|
||||
aabb.y = v.y - aabb.h
|
||||
normal.y = -1
|
||||
elseif dy < 0 then
|
||||
aabb.y = v.y + v.h
|
||||
normal.y = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return normal
|
||||
end
|
||||
|
||||
function collision.aabb_check(a, b)
|
||||
return a.x < b.x + b.w and b.x < a.x + a.w and a.y < b.y + b.h and b.y < a.y + a.h
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
vector = {}
|
||||
vector.utils = {}
|
||||
|
||||
function vec(x, y)
|
||||
return {
|
||||
x = x,
|
||||
y = y,
|
||||
}
|
||||
end
|
||||
|
||||
function vector.utils.input_vector()
|
||||
local vec = { x = 0, y = 0 }
|
||||
vec.x = vector.utils.bool_to_int(input.held(input.RIGHT)) - vector.utils.bool_to_int(input.held(input.LEFT))
|
||||
vec.y = vector.utils.bool_to_int(input.held(input.DOWN)) - vector.utils.bool_to_int(input.held(input.UP))
|
||||
return vec
|
||||
end
|
||||
|
||||
function vector.utils.bool_to_int(b)
|
||||
if b == true then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user