I have this game where there is a ball, and when it hits the paddle, the ball should reflect of the paddle.
Does anyone know the code for this?
Here is my current code for the ball:
{
public void act()
{
move(3);
atWorldEdge();
moveAround();
}
public boolean atWorldEdge()
{
if (getX() <= 5 || getX() >= getWorld() . getWidth() -5)
return true;
if (getY() <= 5 || getY() >= getWorld() . getHeight() -5)
return true;
else
return false;
}
private void moveAround()
{
move(5);
if (atWorldEdge())
{
turn(Greenfoot.getRandomNumber (30) - 30);
}
}
}