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

2019/5/28

I want my rain drops to fall down vertically. What is the code.

lucky555 lucky555

2019/5/28

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

/**
 * Write a description of class Raindrop here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Raindrop extends Actor
{
    public Raindrop()
    {
        reSize();
    }
    
     public void reSize()
    {
        GreenfootImage image = getImage();  
        //System.out.println("Width: "+image.getWidth()+"\nHeight: "+image.getHeight());
        image.scale(50, 50);
        setImage(image);
    }
    
    /**
     * Act - do whatever the Raindrop wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // Add your action code here.
    }    
}
lucky555 lucky555

2019/5/28

#
I should have put in a "?" please excuse my tone.
loldertroll loldertroll

2019/5/28

#
try
move(//place a number as the speed );
setRotation(90);
Super_Hippo Super_Hippo

2019/5/28

#
setLocation(getX(), getY()+1);
lucky555 lucky555

2019/5/29

#
Thank you so much this worked perfectly!
lucky555 lucky555

2019/5/29

#
We want the Bone class once it is touched by the Dog class to pile up the bones in the right corner of the World.
lucky555 lucky555

2019/5/29

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

/**
 * Bone fload along in the field. They are bad. Best to destroy
 * them if you can.
 * 
 * @author Michael Kölling
 * @version 0.1
 */
public class Bone extends Actor
{
    private int speed; 
    /**
     * Constructor. Nothing to do so far.
     */
    public Bone()
    {
        speed = Greenfoot.getRandomNumber(3) + 1;
        reSize();
    }

     public void reSize()
    {
        GreenfootImage image = getImage();  
        //System.out.println("Width: "+image.getWidth()+"\nHeight: "+image.getHeight());
        image.scale(50, 50);
        setImage(image);
    }
    
    /**
     * Float along the field, slowly rotating.
     */
    public void act() 
    {
        setLocation(getX()-speed, getY());
        turn(1);
        
        if (getX() == 0) 
        {
            Field field = (Field)getWorld();
            field.addScore(-15); //now when Bone escape from the World 15 points is subtracted.  
            field.removeObject(this); // Instead of calling getWorld() again do not need to do this be we have already stored in our local variable all of the code .
        }
    }
}
lucky555 lucky555

2019/5/29

#
lucky555 wrote...
We want the Bone class once it is touched by the Dog class to pile up the bones in the right corner of the World. Any ideas on the code I need to add to make this happen? Thanks for any suggestions.
danpost danpost

2019/5/29

#
lucky555 wrote...
We want the Bone class once it is touched by the Dog class to pile up the bones in the right corner of the World.
You want to add a new state to the bones. The state of being collected or not. States are described by fields. Since there are only two possible states for collected (being or not being), a boolean field is in order. After line 43, add code to check for an intersecting Dog object. If found, find a place in the corner for the bone and switch the boolean value. Since the bone must cease and desist in this state, add the following at the beginning of that act method:
if (collected) return;
You need to login to post a reply.