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

2013/10/17

Random Jump

gramcracker1 gramcracker1

2013/10/17

#
I am trying to create a frog that jumps to random spaces every second. When I say jump I mean it disappears and then reappears in different location.
danpost danpost

2013/10/17

#
The jump itself is fairly straight-forward. Get random coordinates and set the location of the object there:
int x = Greenfoot.getRandomNumber(getWorld().getWidth());
int y = Greenfoot.getRandomNumber(getWorld().getHeight());
setLocation(x, y);
All you need now, is a timer field to control the jump rate. Each act cycle, increment the timer and check to see if the value is 50 or so. When it is whatever number you use, execute the jump and set the timer field back to zero.
gramcracker1 gramcracker1

2013/10/20

#
Very straightforward. Thank you for your help ^_^
You need to login to post a reply.