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);
}
}
}
![Twitter](/assets/twitter-4e19209ef84344ee0c433f4c7bad8d49.png)
![Twitter.hover](/assets/twitter.hover-1fb19a5bafc50deace8f88eaec867845.png)