Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualstein102

Posted 30 March 2013 - 12:11 AM

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());
			}	
		}

#2stein102

Posted 30 March 2013 - 12:11 AM

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?

 

		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());
			}	
		}

#1stein102

Posted 30 March 2013 - 12:10 AM

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?

 

		if (ball.ballCircle.intersects(paddle.paddleRect)) {
			//Temporary fix
			//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());
			}	
		}

 


PARTNERS