this is a very interesting thing ive come across. one of the things that chapter 8 in the textbook teaches us is how to make a ball move inside a box and once it hits the walls it is to bounce off. i was able to do that. now im trying to make the balls move but i want them to move only in a straight line and if they hit a wall bounce back. the rotation for them is initially 90 and once they hit the wall they are to make a complete turn and come back at a rotation of 270. but the code im putting in doesnt work. the ball initially moves at a rotation of 90 but when it hits the wall it stays there. here is the code
this is what i tried first
so where am i wrong?
public void bounce()
{
int x = getX();
int y = getY();
setRotation(90);
move(5);
if (x == getWorld().getWidth() -1 || x == 0 || y == 0 || y == getWorld().getHeight() -1 )
{
if (getRotation()== 90)
{
setRotation(270) ;
}
if (getRotation() == 270 )
{
setRotation(90);
}
}
public void bounce()
{
int x = getX();
int y = getY();
setRotation(90);
move(5);
if (x == getWorld().getWidth() -1 || x == 0 || y == 0 || y == getWorld().getHeight() -1 )
{
setRotation(- getRotation()) ;
}
}
