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

2015/10/16

How to let my actor walk on platforms

madflac madflac

2015/10/16

#
cant figure it out.. would be nice if someone could help me ;D my actor:
import greenfoot.*;

public class character extends Actor
{
    private int vSpeed=0;
    
    private int ySpeed;
    private int apexTimer;
    
 
    public character()
    {}
   
    public void act() 
    {
        checkKeys();
        onGround();

}
public void checkKeys()
{ if (Greenfoot.isKeyDown ("D"))
        {move (4);
            setImage("gun_rechts.png");}
        if (Greenfoot.isKeyDown ("A"))
        {move (-4);
        setImage("gun_links.png");}
        if (Greenfoot.isKeyDown ("W"))
        {setImage("gun_oben.png");}
        if (Greenfoot.isKeyDown ("S"))
        {setImage("gun_unten.png");}
    }
    public void onGround()
    {
        int groundLevel = getWorld().getHeight() - getImage().getHeight()/2;
        boolean onGround = (getY() == groundLevel);
        if (!onGround) 
        {
            if (ySpeed == 0 && apexTimer > 0) apexTimer--; 
            if (ySpeed == 0 && apexTimer > 0) return; 
            ySpeed++; 
            setLocation(getX(), getY()+ySpeed);
          
            if (getY()>=groundLevel) 
            {
                setLocation(getX(), groundLevel); 
                Greenfoot.getKey(); 
           }
        }
        else // on ground
        {
            if ("space".equals(Greenfoot.getKey())) 
            {
                ySpeed = -15; // add jump speed
                setLocation(getX(), getY()+ySpeed); 
                apexTimer = 5;  
            }
    }    
}


}
danpost danpost

2015/10/16

#
Maybe you could look at the code of my Jump and Run Demo w/Moving Platform scenario. Just run the project here on the site and click the 'Who' button to view the code.
madflac madflac

2015/10/17

#
Thanks , danpost! Here's his scenario if anybody tries to search it now ->CLICK HERE
madflac madflac

2015/10/17

#
Oh lol you also linked it xd
RadiantCheddar RadiantCheddar

2015/10/20

#
where is the who button?
danpost danpost

2015/10/20

#
RadiantCheddar wrote...
where is the who button?
danpost wrote...
Maybe you could look at the code of my Jump and Run Demo w/Moving Platform scenario. Just run the project here on the site and click the 'Who' button to view the code.
If you had followed the instructions given, you would find it centered along the bottom edge of the scenario window.
RadiantCheddar RadiantCheddar

2015/10/21

#
Oh i was looking at the web page not the scenario sorry
You need to login to post a reply.