A brief query on collision detection
Posted: Wed Sep 09, 2009 10:37 am
Hey Everyone,
I've recently began implementing some collision detection in a small game I'm working on in SDL/C++. I've got it working for basic projectiles that travel in a straight line along the Y axis and collide with enemies that travel in the opposite direction. My main question is on how the collision function accepts its arguments. The way I had initially performed this was by having the function accept a projectile and enemy object pointer and make its calculations based on that, but I realized pretty quickly that this is sloppy for several reasons (passing a lot of unnecessary data to the function, cannot port the collision detection to other types of objects, etc...). Would it be a better idea to have an accessor function in each object that returns its SDL_Rect(x,y,w,h) and have the collision detection function accept 2 of these as its formal parameters? I assume this will give me the freedom of using this function for essentially any object. Trying to keep it simple here for now.
-Hurst
I've recently began implementing some collision detection in a small game I'm working on in SDL/C++. I've got it working for basic projectiles that travel in a straight line along the Y axis and collide with enemies that travel in the opposite direction. My main question is on how the collision function accepts its arguments. The way I had initially performed this was by having the function accept a projectile and enemy object pointer and make its calculations based on that, but I realized pretty quickly that this is sloppy for several reasons (passing a lot of unnecessary data to the function, cannot port the collision detection to other types of objects, etc...). Would it be a better idea to have an accessor function in each object that returns its SDL_Rect(x,y,w,h) and have the collision detection function accept 2 of these as its formal parameters? I assume this will give me the freedom of using this function for essentially any object. Trying to keep it simple here for now.
-Hurst