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

2014/4/13

Setting positions for objects in World

jlee2014 jlee2014

2014/4/13

#
My game is a sea turtle trying to get to the sea. I have trash set up at random places all across the board using this code in World Class: addObject(new Trash(), Greenfoot.getRandomNumber(800), Greenfoot.getRandomNumber(560)); The problem is that if I start a new game and the trash is already touching the turtle the game ends right away. I was wondering if there is a way to keep the trash in the vicinity starting at x coordinate 147 and y coordinate of 560. This way the trash starts a little farther out in the board. Thank you for your help
danpost danpost

2014/4/13

#
Instead of 'Greenfoot.getRandomNumber(800)' use '147+Greenfoot.getRandomNumber(800-147)'; and similar for the y-coordinate.
jlee2014 jlee2014

2014/4/13

#
Thank you! :) It worked great
You need to login to post a reply.