|
@@ -1,10 +1,7 @@
|
|
local Collision = class()
|
|
local Collision = class()
|
|
Collision.cellSize = 128
|
|
Collision.cellSize = 128
|
|
-Collision.onCollide = function(_, a, b, dx, dy)
|
|
|
|
- a, b = a.owner, b.owner
|
|
|
|
- f.exe(a.collision.with and a.collision.with[b.collision.tag], a, b, dx, dy)
|
|
|
|
- f.exe(b.collision.with and b.collision.with[a.collision.tag], b, a, -dx, -dy)
|
|
|
|
-end
|
|
|
|
|
|
+
|
|
|
|
+local check = {}
|
|
|
|
|
|
function Collision:init()
|
|
function Collision:init()
|
|
self.hc = require 'lib/hc'
|
|
self.hc = require 'lib/hc'
|
|
@@ -44,22 +41,21 @@ function Collision:move(data)
|
|
end
|
|
end
|
|
|
|
|
|
data.object.shape:moveTo(x, y)
|
|
data.object.shape:moveTo(x, y)
|
|
-end
|
|
|
|
|
|
|
|
-function Collision:update()
|
|
|
|
- --[[for shape in self.hc:activeShapes() do
|
|
|
|
- if shape.owner then
|
|
|
|
- self:move({object = shape.owner})
|
|
|
|
- end
|
|
|
|
|
|
+ if data.resolve then
|
|
|
|
+ self:resolve(data.object)
|
|
end
|
|
end
|
|
|
|
+end
|
|
|
|
|
|
- self.hc:update()
|
|
|
|
|
|
+function Collision:resolve(object)
|
|
|
|
+ local a = object
|
|
|
|
+ local check = {}
|
|
|
|
|
|
- for shape in self.hc:activeShapes() do
|
|
|
|
- if shape.owner then
|
|
|
|
- self:move({object = shape.owner})
|
|
|
|
- end
|
|
|
|
- end]]
|
|
|
|
|
|
+ for other, vector in pairs(self.hc.collisions(object.shape)) do
|
|
|
|
+ local b, dx, dy = other.owner, vector.x, vector.y
|
|
|
|
+ f.exe(a.collision.with and a.collision.with[b.collision.tag], a, b, dx, dy)
|
|
|
|
+ f.exe(b.collision.with and b.collision.with[a.collision.tag], b, a, -dx, -dy)
|
|
|
|
+ end
|
|
end
|
|
end
|
|
|
|
|
|
function Collision:pointTest(x, y, options)
|
|
function Collision:pointTest(x, y, options)
|