   simple circle and rectangle collision detection
  I am making a breakout game using allegro and C++.  The whole game uses primitive shapes, no sprites or anything like that.  The ball is a circle and the paddle is a rectangle.  The collision detection i have right now works pretty well.  I take the farthest pixel, down, right, left, down and right, down and left on the ball and check to see if its equal to the color of the paddle.  If it is then its a collision.  I don't bother checking any of the up directions since the ball will always be moving down when it hits the paddle.This method works pretty well although sometimes, maybe once or twice a game it seems that the ball will bounce around within the paddle and then fall through the paddle.  Is there a better way to do collision detection?  The method i thought about involves something with the area of the rectangle and the circumference of the circle and detecting a collision that way.  However, i don't exactly know how this would work.  Any suggestions on a better collision detection method of a circle on a rectangle?Thanks.   
  You could use the Separating Axis Theorem for circle vs box.Alternatively, you could just do a swept cirlce vs line segment (personally I'm a fan of sweep testing).  The circle is only going to hit the top part of the paddle.  No need to worry about the other 3 edges.  I had a hard time finding tutorials/equations on how to do this when I first did it.  I started this thread, which might be a small benefit to you.  I also have working code for doing swept circle vs line segment testing which I'd be happy to share/explain.   ;  You can do a lazy evaluation  (simpler/cheaper one first to cull obvious overlaps)by turning the circle into another rectangle and test rectangle-rectangle  first.If it collides on this test then you can do a more exact/expensive test to determine the true collision.   For some uses the rect-rect test is good enough by itself.   ;  wodinoneeye,I have thought about drawing a rectangle around the circle but how would i test for collision?  I would still be testing pixels right?  I would have to test every pixel around the entire rectangle right?MikeTacular,I looked into the swept circle vs line test and the only part i understand is you look for when the middle of the circle hits the line that makes up the top of the rectangle, then its a collision or something like that?  If you are willing an example would help.Thanks to you both.   ;  Hi,For the solution proposed by Woodinoneeye, you will have two level of collision testing:- test the bounding rextangle of the circle with the bounding rectangle of the box. If they do not intersect, stop here.- if the bounding rectangles intersect, you do a more expensive test to see if the circle really intersects box (pixel masks for example).A variant, if you do not wish to make expensive testing, is to only test for bounding rectangles. But, the bounding rectangle of the circle will be a tad smaller in size to encompass more than 90% of the circle area: this reduces the empty spaces within the circle bounding rectangle.Ghostly yours,Red.   ;  I think the rectangle inside the circle idea is what i am doing because i check 5 points on the edge of the circle, left, right, down, down and left, down and right.  Isn't this the same as the rectangle inside the circle except its an imcomplete rectangle because i don't have to check the points up because the ball will always be in a downward motion when hitting the paddle?  Also, i check pixels for the collisions.  For example, i check if the farthest pixel in each direction is the color of the paddle, if it is then its a collision.  Should i be checking if x and y points are equal and not the pixel colors?  If so how do i test the whole of the rectangle that makes up the paddle?   ;  For rectangle - rectangle collision, you can use simple logic. For circle - circle collision, use the distance formula, and if the distance between the two points is less than the sum of the two radiuses, then they collide. The distance formula is:d = sqrt((x1-x2)^2 + (y1-y2)^2)d = the distance, x1 and y1 is the coordinates of the center point of the first circle.x2 an y2 are the coordinates of the center point of the second circle.   ;  Well, in breakout, everything is going to be aligned with the axii. (That is the correct plural of axis?) What I would do would go something like this:for(int i=0; i<BLOCKNUM; i++){ if(ball.x>brick.x && ball.x<brick.x+brick.w && ball.y>brick.y && ball.y<brick.ybrick.h) { ball.vy=-ball.vy; brick.alive=false; }}NOTE: Not tested, so if it doesn't work, sorry!   