in a BrickBreaker-game I have the following code to check the collision of the ball with the bar:
if(ball.x + ball.getWidth() > bar.x && ball.x < bar.x + (bar.getWidth()/5)) {
...
}
else if(ball.x + ball.getWidth() > bar.x + (bar.getWidth()/5) && ball.x < bar.x + (2*bar.getWidth()/5)) {
...
}
else if(ball.x + ball.getWidth() > bar.x + (2*bar.getWidth()/5) && ball.x < bar.x + (3*bar.getWidth()/5)) {
...
}
else if(ball.x + ball.getWidth() > bar.x + (3*bar.getWidth()/5) && ball.x < bar.x + (4*bar.getWidth()/5)) {
...
}
else if(ball.x + ball.getWidth() > bar.x + (4*bar.getWidth()/5) && ball.x < bar.x + bar.getWidth()) {
...
}
but still if the ball doesn't hit the bar, it says, that a collision happened. What's wrong with my collision checking?