[gameprogrammer] Re: storing lists of units

Roger D. Vargas wrote:
> I need to store the list of NPCs in my game, and Im looking the best way
> to do so. I need to be able to quickly find only the ones closer to
> certain location to pass them to my lua script. Whats the best structure
> and algorithm to do this?
>   
> 

Try using space sub-division.  So if it's a 2D game, divide the screen 
up into say 8 rectangluar areas, each area has an associated list that 
stores the NPC's that are entirely in the area or overlapping into the 
area.  When you move an  NPC you can update which lists it appears in.

All you need to do to is find which area(s) your location is in, and 
then the lists will tell you which items are close.


- Tom



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: