In the "flat" code for the "Obstacle" example you are given the function
bool IntersectRects( const Rect& r1, const Rect& r2 ){ return ! ( r1.bottom < r2.top || r2.bottom < r1.top || r1.right < r2.left || r2.right < r1.left ); }that returns true is the Rects r1, r2 intersect, and false otherwise. This function makes detecting collisions very straightforward. Namely, you only need to prepare the two Rects bounding the two objects you want to check for an overlap, and give them to this function. To make a struct Rect out of four coordinates, you can use the standard CoreTools function
Rect MakeRect( int x1, int y1, int x2, int y2 );For example, a ball with the center at (x,y) and radius r is bounded by the rectangle with the corners (x-r,y-r) and (x+r,y+r). The corresponding struct Rect will be made and returned by
MakeRect( x-r, y-r, x+r, y+r )
MakeRect( left, top, right, bottom ) and MakeRect( nx-r, ny-r, nx+r, ny+r )overlap. Detecting this collision is all that
bool Ball::Collides( const Wall& w );needs to do.
MakeRect( nx-r, ny-r, nx+r, ny+r ) and MakeRect( b.x - b.r, b.y - b.r, b.x + b.r , b.y + b.r )The second rectangle is the one that bounds the other ball b. Checking if these two rectangles overlap is all that
bool Ball::Collides( const Ball& b );needs to do.