Hi all,
I am new to game programming. I am trying to write a simple game and I would like to know how to differentiate two rectangular bitmaps at run time. I have more than two types of bitmaps flying around in the screen when I shoot I need a mechanism to dectect what type of bitmap got the bullet. I know how to dectect the collision but how will I know what type of bitmap was it ? do I have to write a class for each category of bitmaps ? how will I get the object when there is a collision (ie. it's been hit ). May be I am missing something stupid...
Please give me some ideas. I am good at programming, so just I need some advice.
Thanks
how to differentiate two rectangular bitmaps
Started by freefly, Dec 06 2006 03:18 PM
4 replies to this topic
#1
Posted 06 December 2006 - 03:18 PM
#2
Posted 06 December 2006 - 04:41 PM
Well, you are rendering the objects, so your program has to know where each one is and what bitmap it uses, right? At the point you detect a collision, you basically loop through the objects and check for a collision with each one, so when you detect one you know what object it is, don't you? You don't have to write a separate class for each kind of object in your game, but it's a good idea, if you might want the objects to have different behavior sometime later.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 06 December 2006 - 05:12 PM
Thank you very much... just got confused. I was wondering whether there is any efficient way to do it, rather than looping through all the bitmaps on the screen. if any please tell me.
thanks again
thanks again
#4
Posted 06 December 2006 - 08:05 PM
Ahh. Yes, you can definitely speed that up; one way is to divide the screen up into a grid, and maintain a list of which objects are in each grid square - an object can be in more than one square if it overlaps a corner or an edge, and the lists need to be updated when the objects move. Then, to check for collisions, you don't need to check all the objects but only objects in the grid squares that overlap the bullet.
reedbeta.com - developer blog, OpenGL demos, and other projects
#5
Posted 11 December 2006 - 12:11 PM
thank you very much that is a good idea.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











