Rename HC:testPoint to HC:shapesAt. More efficient implementation.

This commit is contained in:
Matthias Richter 2012-03-05 10:37:36 +01:00
parent 1fd4dff37e
commit 8a182a902f

View File

@ -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