So, now all of my game objects have a collision detection polygon overlaid (invisibly) on top of the images. Great!
The problem is that HC doesn't know anything about my game objects. All it knows about are collision detection shapes that have been created in its spacial hash by game objects. Collision detection is done in the main file similar to this:
Code: Select all
-- check for collisions
for shape, delta in pairs(HC.collisions(player.collisionShape)) do
-- How do I get from shape to a GameObject that has this shape
-- so that I can remove the GameObject from a table of enemies
end
I can search through the table of active enemies looking for a collision shape with the same coords as the shape returned by HC. That seems slow.
I can add a parent reference to GameObject inside the shape, but that still leaves the problem of where the GameObject is in the table. I suppose, I could add an index to every GameObject that identifies where in the list it is, but then I would have to update indexes as enemies are removed form the table. Maybe there's a way I can use a unique key (or ID) to store enemies in the table. This would then allow me to get a GameObject reference from shape and get a GameObject key that is then used to remove the GameOject instance form the table.
Any ideas?