Results 1 to 3 of 3
Thread: Greenfoot help
- 05-17-2012, 02:28 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 12
- Rep Power
- 0
Greenfoot help
I am wanting to add a new actor in greenfoot at a random location
that is my code but the commented "int y = Greenfoot.getRandomNumber(450" is supposed to be the random location on the Y-axis, I already have the X-axis, but I need to set a limit on the y axis so that 450 is the highest from the bottom of the world which is 800. Any help is appreciatedJava Code:long lastAdded = System.currentTimeMillis(); public void act() { long curTime = System.currentTimeMillis(); if (curTime >= lastAdded + 4000) //5000ms = 5s { MyWorld world; world = (MyWorld) getWorld(); int x = Greenfoot.getRandomNumber(600); //int y = Greenfoot.getRandomNumber(450 world.addObject(new WoundedPerson(), x, 450); lastAdded = curTime; }
- 05-17-2012, 02:34 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Greenfoot help
int y = 800-Greenfoot.getRandomNumber(450);
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-17-2012, 03:24 PM #3
Senior Member
- Join Date
- Feb 2012
- Posts
- 117
- Rep Power
- 0
Re: Greenfoot help
So would that be 0-450, or 450-800? Depending on the implementation of getRandomNumber in Greenfoot, you might have to do some subtraction if it's the latter case.I need to set a limit on the y axis so that 450 is the highest from the bottom of the world which is 800.
This probably will need changed too, right?world.addObject(new WoundedPerson(), x, 450);
Similar Threads
-
Scaling an object in Greenfoot
By Tayl0r in forum Java GamingReplies: 0Last Post: 12-03-2010, 10:05 PM -
Using Applets built in GreenFoot?
By sciguy77 in forum New To JavaReplies: 0Last Post: 01-19-2009, 08:43 PM -
Greenfoot exporting in .jar?
By sciguy77 in forum New To JavaReplies: 0Last Post: 01-18-2009, 07:06 PM -
Greenfoot 1.4.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 03-24-2008, 06:02 PM -
Greenfoot 1.2.1
By Jamie in forum Java SoftwareReplies: 0Last Post: 06-14-2007, 02:54 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks