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

2016/2/29

HELP

PaoloLim17 PaoloLim17

2016/2/29

#
hi, im having trouble with my code. i managed to make the first actor fall ( the patty) but i dont know how to make the other actors fall
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class patty here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class patty extends Actor
{
    public void act() 
    {
        //move(-10);
        setLocation(getX(),getY()+1);
        if(isAtEdge())
        {
            getWorld().removeObject(this);
        }
        
        if(isTouching(player.class))
        {
            //Greenfoot.playSound("ding.mp3");
            //removeTouching(player.class);
            getWorld().removeObject(this);
            //MyWorld world=(MyWorld) getWorld();
            
        }
        
    }    
     public void moveDown(){
          int xpos = getX(); // find out the current Y position and store it
            if (xpos < getWorld().getWidth() - 10)
                {
                        xpos = xpos +2;
                        setLocation(getY(), xpos);
                        
                    } else {
                        getWorld().removeObject(this);
                    }
}
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class lettuce here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class lettuce extends Actor
{
    public void act() 
    {
        //move(-5);
        setLocation(getX(),getY()+1);
        if(isAtEdge())
        {
            getWorld().removeObject(this);
        }
        /*
        if(isTouching(player.class))
        {
            //Greenfoot.playSound("ding.mp3");
            //removeTouching(player.class);
            getWorld().removeObject(this);
            //MyWorld world=(MyWorld) getWorld();
            
        }
        */
    }    
     public void moveDown(){
          int xpos = getX(); // find out the current Y position and store it
            if (xpos < getWorld().getWidth() - 10)
                {
                        xpos = xpos +2;
                        setLocation(getY(), xpos);
                        
                    } else {
                        getWorld().removeObject(this);
                    }
                }
                
}
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class cheese here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class cheese extends Actor
{
    public void act() 
    {
        //move(-5);
        setLocation(getX(),getY()+1);
        if(isAtEdge())
        {
            getWorld().removeObject(this);
        }
        /*
        if(isTouching(player.class))
        {
            //Greenfoot.playSound("ding.mp3");
            //removeTouching(player.class);
            getWorld().removeObject(this);
            //MyWorld world=(MyWorld) getWorld();
            
        }
        */
    }    
     public void moveDown(){
          int xpos = getX(); // find out the current Y position and store it
            if (xpos < getWorld().getWidth() - 10)
                {
                        xpos = xpos +2;
                        setLocation(getY(), xpos);
                        
                    } else {
                        getWorld().removeObject(this);
                    }
                }
                
}
danpost danpost

2016/2/29

#
I see an issue with the patty class (one where an run-time error will occur); but, I do not see any issues (other than methods that are not being called; at least, not that I can see) with the other ones. Maybe you should post your MyWorld class code.
You need to login to post a reply.