This is my code for the ball colliding with the paddle in my game. As of right now, if the ball approaches the paddle and hits it on the corner, the ball seems to get trapped inside of the paddle. Any suggestions?
I'm using the Slick2d API if it makes a difference.
if (ball.ballCircle.intersects(paddle.paddleRect)) {
//left
if(ball.ballCircle.getMaxX() <= paddle.paddleRect.getMinX()){
ball.ballCircle.setCenterX(paddle.paddleRect.getMinX()-ball.ballCircle.getRadius()-1);
ball.setDx(-ball.getDx());
}
//Right
if( ball.ballCircle.getMinX() >= paddle.paddleRect.getMaxX()){
ball.ballCircle.setCenterX(paddle.paddleRect.getMaxX()+ball.ballCircle.getRadius()+1);
ball.setDx(-ball.getDx());
}
//Top
if(ball.ballCircle.getMaxY() <= paddle.paddleRect.getMinY()){
ball.ballCircle.setCenterY(paddle.paddleRect.getMinY()-ball.ballCircle.getRadius()-1);
ball.setDy(-ball.getDy());
}
}