From b58631465ca7e9dc9e1ed6e98bccce5d3c018047 Mon Sep 17 00:00:00 2001 From: "Danny \"TechnoCat\" Fritz" Date: Sat, 3 Mar 2012 20:06:39 -0600 Subject: [PATCH] Added HC:testPoint(x, y) -- Test point for collisions with active objects. --- init.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/init.lua b/init.lua index 2f7bb3c..6855f83 100644 --- a/init.lua +++ b/init.lua @@ -191,6 +191,27 @@ function HC:update(dt) self._colliding_last_frame = colliding end +-- Test point for collisions with active objects +function HC:testPoint(x, y) + -- collect colliding shapes + local point = newPointShape(x,y); + new_shape(self, point); + + local colliding = {}; + for _,shape in pairs(point:_getNeighbors()) do + if shape:collidesWith(point) then + table.insert(colliding, shape); + end + end + + self:remove(point); + + if #colliding == 0 then + return false; + end + return colliding; +end + -- remove shape from internal tables and the hash function HC:remove(shape, ...) if not shape then return end