This site requires JavaScript, please enable it in your browser!
Greenfoot back
Moynzy
Moynzy wrote ...

2014/1/7

Set random Location

Moynzy Moynzy

2014/1/7

#
Hey guys, I want to thank everyone for helping me out in the last month or so. I have one more problem and then I will never bother you guys again.
  public void CheckFollowplayer()
    {
        //move Down
        Actor FollowBall;
        FollowBall=getOneObjectAtOffset(0,-10,FollowBall.class);
        if (FollowBall !=null)
        {

            setLocation(getX()+ 40, getY() + 3);
            Greenfoot.getRandomNumber(20)-10);
            //For the basic solution this is where you put your new code.
        }
    }
    
I want the locations to be random. I.E setLocation(getX()+ random int , getY() + random int); Thank you for taking your time, most appreciated
erdelf erdelf

2014/1/7

#
this should work
setLocation(getX()+ Greenfoot.getRandomNumber(40)-20, getY() + Greenfoot.getRandomNumber(40)-20);  
Moynzy Moynzy

2014/1/7

#
erdelf wrote...
this should work
setLocation(getX()+ Greenfoot.getRandomNumber(40)-20, getY() + Greenfoot.getRandomNumber(40)-20);  
God bless you, Best of luck everyone, was a pleasure. Thank you.
You need to login to post a reply.