   need help debugging my Breakout collision detection code
  Hi all.I am developing a clone of the breakout game. I have successfully implemented the collision with the paddle and walls, the bricks part is the one that's giving me some headaches.I have this code, it may not be very efficient, but I just tried to make it easy to program and understand, but for some reason, I have not discovered yet and that's why I am asking your help for, it doesn't work.In the code ball.x and ball.y are coordinates for the center of the ball and level.bricks.x and level.bricks.y are the coordinates for the left upper most corner of the brick.Here it is:bool ballHitsBricks(){int i;for (i = 0; i < level.number_of_bricks; i++){int x0, x1, y0, y1;x0 = level.bricks.x;x1 = x0 + level.bricks.width;y0 = level.bricks.y;y1 = y0 - level.bricks.height;//determine in which "quadrant" the ball is in relation to the brickbool q1, q2, q3, q4;if (ball.x >= x0 && ball.x <= x1){if (ball.y <= y0) q1 = true;else if (ball.y >= y1) q3 = true;}if (ball.y <= y1 && ball.y >= y0){if (ball.x <= x0) q2 = true;if (ball.x >= x1) q4 = true;}bool bq1, bq2, bq3, bq4; //flags to know in each "quadrant" has the ball hit the brickif (q1 && ball.y+ball.radius >= y0) bq1 = true;if (q4 && ball.y-ball.radius <= y1) bq4 = true;if (q2 && ball.x+ball.radius >= x0) bq2 = true;if (q3 && ball.x-ball.radius <= x1) bq3 = true;if (bq1 || bq3) ball.vy = -ball.vy;if (bq2 || bq4) ball.vx = -ball.vx;if (bq1 || bq2 || bq3 || bq4) return true;return true;}return false;}Thanks in advance.
  You haven't said what the problem is, so I'm going to guess that the ball just doesn't collide with the bricks at all, but passes through them?At the end of your loop, you have a return true. You should be continuing to the next brick instead:if (bq1 || bq3) ball.vy = -ball.vy;if (bq2 || bq4) ball.vx = -ball.vx;if (bq1 || bq2 || bq3 || bq4) return true;}