🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

detect collisions within a list?

Started by
0 comments, last by Jimbo 24 years, 5 months ago
I use one single "class-list" for all my sprites - missiles as well as the enemies that I frequently update to animate them and such. Now I wonder if there is a way to keep track of collissions within the list, or if it''s better to have to seperate lists for enemies and missiles?
Advertisement
If you want to do regular collision box detecting, you should make a function for your sprites called getCollisionBox() which would return a Rectangle of it''s bounding box, or it''s upperleft x,y and height width attributes. When you are going through your list, make another list of objects that have moved in the past update, maybe make a boolen for each sprite and set them all to false after each update cycle of the engine. Take this smaller list of moved objects and test to see if their bounding collision boxes intersect those of other sprites in the same sprite level (if you have multiple sprite levels). Alternatively, you can just check the list of moved sprites against only a list of missles and enemies.

hope that helps

This topic is closed to new replies.

Advertisement