Hi,
I'm trying to create a world where the object moves and when it hits the edge it bounces back into the opposite direction. I figured out how to make it move to the other side but not how to bounce it off.
Here's my code so far-
public void act()
{
move(+12);
if(getX() == (getWorld().getWidth()-1))
{
setLocation(0, getY());
}
else if(getX() == 0)
{
setLocation(getWorld().getWidth(), getY());
}
if(getY() == (getWorld().getHeight()-1))
{
setLocation(getX(), 0);
}
else if(getY() == 0)
{
setLocation(getX(), getWorld().getHeight());
}
}
}