Results 1 to 3 of 3

Thread: Greenfoot help

  1. #1
    Big-D is offline Member
    Join Date
    Mar 2012
    Posts
    12
    Rep Power
    0

    Default Greenfoot help

    I am wanting to add a new actor in greenfoot at a random location
    Java 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;
            }
    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 appreciated

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: Greenfoot help

    int y = 800-Greenfoot.getRandomNumber(450);

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Diargg is offline Senior Member
    Join Date
    Feb 2012
    Posts
    117
    Rep Power
    0

    Default Re: Greenfoot help

    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.
    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.

    world.addObject(new WoundedPerson(), x, 450);
    This probably will need changed too, right?

Similar Threads

  1. Scaling an object in Greenfoot
    By Tayl0r in forum Java Gaming
    Replies: 0
    Last Post: 12-03-2010, 11:05 PM
  2. Using Applets built in GreenFoot?
    By sciguy77 in forum New To Java
    Replies: 0
    Last Post: 01-19-2009, 09:43 PM
  3. Greenfoot exporting in .jar?
    By sciguy77 in forum New To Java
    Replies: 0
    Last Post: 01-18-2009, 08:06 PM
  4. Greenfoot 1.4.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-24-2008, 07:02 PM
  5. Greenfoot 1.2.1
    By Jamie in forum Java Software
    Replies: 0
    Last Post: 06-14-2007, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •