oh ok, so this is what I have. it worked one way then did not come bake the other way and it it not running off the mouse click... I know I did some thing wrong just not sure what that is.
public class Ball extends Actor
{
private int oldX ;
private int newX ;
private int direction ;
public Ball()
{
oldX = 0;
newX = 0;
direction = 1;
}
public void act()
{
oldX= getX();
if (Greenfoot.mousePressed(this)){
int deltaX = Greenfoot.getRandomNumber(100);
// You need to store the store the current location of the ball at oldX
// that newX can be obtained based on it.
newX = oldX + deltaX * direction;
if (newX > getWorld().getWidth()-1){
newX = getWorld().getWidth() -1;
}
if (newX < 0){
newX =0;
}
}
if (oldX != newX){
// The ball keeps moving towards newX only when it is not there yet.
// As soon as it reaches newX, it stops moving.
setLocation(getX()+direction, getY());
}
if (getX() == 0 || getX() == getWorld().getWidth() -1)
{
direction = -direction;
}
}
}

