I’m using rectangles and checking bounds when they overlap…Sometimes, a whole row of brick disappears! When the brick is hit is sets isVisible to false and I have a check setup so that when it is not visible it takes 1 away from brickcount. Here is my collision code:
if (brick.GetVisible()==true)
{
if (brick.brickRect.overlaps(ballRect))
{
if (ballRect.x + ballRect.width >= brick.brickRect.x && ballRect.x < brick.brickRect.x) {
ballSpeedX = -ballSpeedX;
brick.isVisible = false;
System.out.println("Left Side");
}
if (ballRect.x <= brick.brickRect.x+brick.brickRect.width && ballRect.x > brick.brickRect.x) {
ballSpeedX = -ballSpeedX;
brick.isVisible = false;
System.out.println("Right Side");
}
if (ballRect.y + ballRect.height >= brick.brickRect.y && ballRect.y < brick.brickRect.y + brick.brickRect.height) {
ballSpeedY = -ballSpeedY;
brick.isVisible = false;
System.out.println("Bottom Side");
}
if (ballRect.y <= brick.brickRect.y+brick.brickRect.height && ballRect.y > brick.brickRect.y + brick.brickRect.height) {
ballSpeedY = -ballSpeedY;
brick.isVisible = false;
System.out.println("Top Side");
}