bool circleRectCollide(SDL_Point circle, float r,
SDL_Rect rect)
{
// does this assume that circle x and circle y are the center of the circle?
float closestX = clamp(circle.x, rect.x, rect.x + rect.w);
float closestY = clamp(circle.y, rect.y, rect.y + rect.h);
// this gets the distance form the center of the circle to a side of a
// rectangle. It could be negative or positive. Because we are squaring them
// it doesn't matter.
float dx = circle.x - closestX;
float dy = circle.y - closestY;
// use the dot product to determine collision
return (dx*dx + dy*dy) <= (r*r);
}