Hi,
I'm trying to make a pong game but I'm having trouble with the ball movement. I have got the ball to bounce off the walls and the paddles using the code below:
private int xSpeed = 3, ySpeed = 3;
public void act()
{
movement();
Actor paddle_1 = getOneIntersectingObject(paddle1.class);
if (paddle_1!=null)
{
xSpeed = -xSpeed;
}
Actor paddle_2 = getOneIntersectingObject(paddle2.class);
if (paddle_2!=null)
{
xSpeed = -xSpeed;
}
playerScore();
}
public void movement()
{
setLocation(getX() + xSpeed, getY() + ySpeed);
if(getY()<5 || getY() > getWorld().getHeight()-5)
{
ySpeed = -ySpeed;
}
}
The problem I'm having is that I want the ball to start off bouncing between two paddles continuously, until a third paddle comes into contact with
the ball. When the ball hits the third paddle I need it to bounce off realistically and then go to the opposite side to score a point like in the game 'Pong'. I hope this makes sense.
I'd really appreciate it if someone could point me in the right direction.
Thanks
