Archived

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

dhscompguy

Using a quadtree in 2D?

Recommended Posts

Hello all, First post so I hope I''m not breaking any rules. I apologize in advance if so. My question involves testing whether or not an object is in the vicinity of an explosion. Let''s say an enemy goes critical and explodes. This triggers an "explosion" event at his current x,y position. The event dispatcher is the first to hear of this. The dispatcher loops through every moving game object and checks whether or not the object is 200 units from the point of the explosion. If so, the object''s ID is pushed into a priority queue with a priority of distance. After these tests are done, the dispatcher pops IDs from the queue, nearest object to farthest, and calls gameObjects[ID].handleEvent(gameEvent). First off, is there a better way to handle this entire process? Secondly, would a quadtree be useful in this situation, where game objects are moving around every game tick and I want to see who is in a particular region at any given time, or would it be overkill (considering it''s a Flash game with very few game objects per level)? If overkill, any other ideas that might enable me to put a few more objects on screen at the same time? Thanks much, Denny

Share this post


Link to post
Share on other sites
Definitely overkill if you have very few objects... if the method you are using works, why bother changing it? Two rules to live by:

1) If it ain''t broke, don''t fix it.
2) Keep It Simple Stupid

Rule #2 basically means that you do the simplest thing possible that accomplishes the tasks.

Share this post


Link to post
Share on other sites