Hi, I am working on a unique brick breaker type game and am having an issue with my collision detection.
I am trying to detect hits on all 4 corners and 4 sides of a brick. It works alright but is kind of glitch and sometimes acts like it hit a corner when it clearly hit close to
the center of a top or side of the brick and vice versa.
The easier way I can explain this is for you to play my game and notice it yourself (should not take long)
AtomicBlocks.jar Download Link
CONTROLS
F1 - Generates new level
WASD
Arrow Keys
Here is my current collision detection code.
Rectangle brickRect = aBlocks.get(i).getBounds();
ABlock block = (ABlock) aBlocks.get(i);
// If we hit on the left
if ((ball.getX() + (ball.getWidth()/2)) < (brickRect.x))
{
ball.setDx(-Math.abs(ball.getDx()));
}
// If we hit on the right
else if ((ball.getX()) > (brickRect.x + (brickRect.width/2)))
{
ball.setDx(Math.abs(ball.getDx()));
}
// If we hit on the top
if ((ball.getY() + (ball.getWidth()/2)) < (brickRect.y))
{
ball.setDy(-Math.abs(ball.getDy()));
}
// If we hit on the bottom
else if ((ball.getY()) > (brickRect.y + (brickRect.height)/2))
{
ball.setDy(Math.abs(ball.getDy()));
}