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

2014/6/9

Danpost this is my problem

docinkc docinkc

2014/6/9

#
I believe I copied all the lines from your game to mine and I get and error message for this(0); saying "call to this must first be a statement in constructor."
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Platform here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Platform extends Actor
{
    int speed;
    public void Platform()
    {
        this(0);
    }
    public Platform(int rate)
    {
        speed=rate;
        
    }
    public void act() 
    {
        if (speed == 0) return;
        int worldWidth = getWorld().getWidth();
        setLocation(getX(),getY()-1);
        Actor Player=getOneIntersectingObject(Player.class);
        setLocation(getX()+speed,getY());
        int dx =(int)Math.signum(speed);
        int dist = speed;
        Actor obstacle = getOneIntersectingObject(null);
        while (obstacle != null)
        {
            setLocation(getX()-dx, getY());
            dist -= dx;
            obstacle = getOneIntersectingObject(null);
        }
        if(Player != null)Player.setLocation(Player.getX()+dist, Player.getY());
        if((speed > 0 &&getX() >= worldWidth-50)||(speed < 0 && getX() <= 50))speed =-speed;
        
    }    
}
danpost danpost

2014/6/9

#
You copied line 12 incorrectly.
docinkc docinkc

2014/6/10

#
danpost wrote...
You copied line 12 incorrectly.
Thank you!
You need to login to post a reply.