Archived

This topic is now archived and is closed to further replies.

Screndib

Need suggestions on organizing game objects.

Recommended Posts

Say I''ve got an tile based action game with shooting, running around, enemies, etc... What I''m having trouble with is figuring out a good way to keep track of all of the objects in the game world. One big list seems like a bad idea because when testing for collision or drawing sprites, I really don''t need to worry about things all the way across the level. My best idea at the time is to break the level into sectors and store the objects into multiple lists so I only have to worry about comparing against a few sectors. This seems like it could get very complex very fast though. Anyone able to reccommend a better way of doing this?

Share this post


Link to post
Share on other sites
You can keep your big list but you may want to sort it between objects on screen and objects off screen. The collision update rate can be lower for offscreen objects (test for collision every 2 seconds) and higher for on screen objects (test each other frame). I guess you will not have much objects on screen at any time (I read on Gamasutra that 20 game objects was a maximum for screen readability), so collision detection will be faster.

Hope that helps,
Ghostly yours,
Red.

Share this post


Link to post
Share on other sites
You could maintain one big list for everything then make multiple list objects that point to selections from the big list. So you would have your AllObjectList, your VisibleObjects list, your MovingObjects list, your BulletObjects list, your SectorAObjectsList and so on.

Your AllObjectsList would of course contain all game objects, whether for rendering or management or whatever. Your other lists would just be lists of pointers to the appropriate objects in the main list. So your BulletObjects list would only point to bullet objects from the main list and your SectorBObjectsList would only have pointers to objects in Sector B. Then all you would have to do is run collision detection between items in your BulletObjects list and either AllObjectsList objects or SectorAObjectsList. You could also make your game client only render objects in the sector that he is in by having him only render SectorBObjectsList when he is in sector B.

Just a thought.

Share this post


Link to post
Share on other sites