I'd personally would rather have:
SDL_CollidePixel( ... )SDL_CollideBoundingBox( ... )SDL_CollideBoundingBox( ... )SDL_CollideBoundingCircle( ... )
... But that's just me.
As for the credit, just put in "Rob Loach (http://www.robloach.net)" anywhere in there. I'm not really that anal about this kind of thing. You can reformat the documentation as much as you want. I wasn't quite sure about the second SDL_CollideBoundingCircle as sometimes a sprite can be only part of an SDL_Surface......
// Declaration (*.h)bool SDL_CollideBoundingCircle(int x1, int y1, int radius1, int x2, int y2, int radius2, int offset = 0);bool SDL_CollideBoundingCircle(SDL_Surface* a, int x1, int y1, SDL_Surface* b, int x2, int y2, int radius1 = -1, int radius2 = -1, int offset = 0);// Definition (*.cpp)#include <cmath>// SDL_CollideBoundingCircle(x1, y1, radius1, x2, y2, radius2, offset)// Checks a collision using the bounding circle of two different sprite objects// x1 - The x center position of the first object// y1 - The y center position of the first object// radius1 - The radius of the first object// x2 - The x center position of the second object// y2 - The y center position of the second object// radius2 - The radius of the second object// offset - Allow some offset between the two objects (0 default)bool SDL_CollideBoundingCircle(int x1, int y1, int radius1, int x2, int y2, int radius2, int offset){ int distx = abs((int)(x1 - x2)); int disty = abs((int)(y1 - y2)); return(sqrt((distx * distx) + (disty * disty)) - radius1 - radius2 <= offset);}// SDL_CollideBoundingCircle(a, x1, y1, b, x2, y2, radius1, radius2, offset)// Checks a collision using the bounding circle of two different sprite objects// a - The SDL_Surface of the first object// x1 - The left position of the first object// y1 - The y center position of the first object// radius1 - The radius of the first object (-1 defaults to the average of the width and height of the surface)// b - The SDL_Surface of the second object// x2 - The x center position of the second object// y2 - The y center position of the second object// radius2 - The radius of the second object (-1 defaults to the average of the width and height of the surface)// offset - Allow some offset between the two objects (0 default)bool SDL_CollideBoundingCircle(SDL_Surface* a, int x1, int y1, SDL_Surface* b, int x2, int y2, int radius1, int radius2, int offset){ if(radius1 == -1) radius1 = (a->w * a->h) / 2; if(radius2 == -1) radius2 = (b->w * b->h) / 2; x1 = x1 + a->w/2; y1 = y1 + a->h/2; x2 = x2 + b->w/2; y2 = y2 + b->h/2; int distx = abs((int)(x1 - x2)); int disty = abs((int)(y1 - y2)); return(sqrt((distx * distx) + (disty * disty)) - radius1 - radius2 <= offset);}
You can reformat anything as much as you want, I don't mind. You'll have to re-do the documentation to fit into the SDL_Collide.h formatting. Remember that I'm not quite sure about using the second SDL_CollideBoundingCircle as sometimes a sprite can be only part of a SDL_Surface (tiles). I also have yet to compile these renditions, so don't freak out if it pops up a couple of errors.
[Edited by - Rob Loach on March 29, 2005 12:12:51 PM]