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

2019/6/7

moving a dog bone to create a dog bone pile

suzbo suzbo

2019/6/7

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Dog here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Dog extends Actor
{
    /**
     * Act - do whatever the Dog wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(3);
        if (isTouching(Bone.class))
        {
            removeTouching(Bone.class);
            Bone2 bone2 = new Bone2();
            getWorld().addObject(bone2,894,(Greenfoot.getRandomNumber(890, 895));//Greenfoot().getRandomNumber(890,880);
        }
    }    
}
suzbo suzbo

2019/6/7

#
I can't get the bone to move to the lower right hand corner of the world randomly. I want to create a bone pile. I keep getting an error with the getRandomNumber method. Thank you in advance for your help.
Super_Hippo Super_Hippo

2019/6/7

#
Try this:
if (isTouching(Bone.class))
{
    removeTouching(Bone.class);
    getWorld().addObject(new Bone2(), 894, 890+Greenfoot.getRandomNumber(6));
}
suzbo suzbo

2019/6/10

#
Perfect - I adjusted the X and Y axis locations, added a higher random number, added randomness to X axis, and achieved the final outcome of a pile of bones - thanks for all your help!
You need to login to post a reply.