mirror of
https://github.com/vrld/HC.git
synced 2024-11-18 12:54:23 +00:00
Rename HC:testPoint to HC:shapesAt. More efficient implementation.
This commit is contained in:
parent
1fd4dff37e
commit
8a182a902f
24
init.lua
24
init.lua
@ -197,25 +197,15 @@ function HC:update(dt)
|
|||||||
self._colliding_last_frame = colliding
|
self._colliding_last_frame = colliding
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Test point for collisions with active objects
|
-- get list of shapes at point (x,y)
|
||||||
function HC:testPoint(x, y)
|
function HC:shapesAt(x, y)
|
||||||
-- collect colliding shapes
|
local shapes = {}
|
||||||
local point = newPointShape(x,y);
|
for s in pairs(self._hash:cell{x=x,y=y}) do
|
||||||
new_shape(self, point);
|
if s:contains(x,y) then
|
||||||
|
shapes[#shapes+1] = s
|
||||||
local colliding = {};
|
|
||||||
for _,shape in pairs(point:_getNeighbors()) do
|
|
||||||
if shape:collidesWith(point) then
|
|
||||||
table.insert(colliding, shape);
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return shapes
|
||||||
self:remove(point);
|
|
||||||
|
|
||||||
if #colliding == 0 then
|
|
||||||
return false;
|
|
||||||
end
|
|
||||||
return colliding;
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- remove shape from internal tables and the hash
|
-- remove shape from internal tables and the hash
|
||||||
|
Loading…
Reference in New Issue
Block a user