i imagine you want to use some kind of spatial indexing to optimize this
http://drdave.co.uk/blog/archive/2010/10/4/Spatial-Indexing
basically the further away objects the less likely it is you need to check them as this will slow your game loop down. or do you only have a small world of objects anyway?
if the number of objects is small enough to loop through without affecting performance you could just get the square of the length of their hypotenuse distance from your original point (no need to squareroot it, you can just work with the square length for speed)
which would be something like (x2-x1)*(y2-y1)
just check that value is within your (radius*radius) value.
for your second question…
if you want to get a list of objects at a point, you could just keep an array of an array
objectsAtPoint[x][y] = {obj1, obj2, obj3} etc
i believe 1-dimensional array would be faster tho (combine x ,y into one value)
see here:
http://www.lua.org/pil/11.2.html
so you’d have objectsAtPoint[1] = {obj1,obj2,obj3} etc
where point 1 is [0,0], point 2 is [1,0], point 3 is [2,0], point 4 is [0,1], point 5 is [1,1] etc
(thats in a 3x3 grid for simplicity of example)
however if your objects are moving, i’m not sure this is the most optimal array to store the data as you’ll have to keep moving objects from 1 array point to another
[import]uid: 6645 topic_id: 4174 reply_id: 12966[/import]