import greenfoot.*;
public class MAN extends Actor
{
private GreenfootImage images1=new GreenfootImage;
private GreenfootImage images=new GreenfootImage;
private int jeda=10,num=0,deltax=30;
public void addedToWorld(World latar)
{
for (int i=0;i<images.length;i++)
{
images=new GreenfootImage("Player"+i+".png");
}
setImage(images);
}
private int speed = 7; //Change number for other speed
private int vspeed = 0; //Change number for other fall speed
private int vspeedplus = 1; //How fast you fall evry sec
private int jumpHeight = -20; //How high you jump
public void act()
{
checkFalling();
if (Greenfoot.isKeyDown("right") )
{
move(speed);
if(jeda==0)jeda=10;
if(jeda==1)
{
setImage(images);
num++;
if(num>=images.length)num=0;
}
if(jeda>0)jeda--;
}
if (Greenfoot.isKeyDown("left") )
{
move(-speed);
if(jeda==0)jeda=10;
if(jeda==1)
{
setImage(images);
num++;
if(num>=images.length)num=0;
}
if(jeda>0)jeda--;
}
if (Greenfoot.isKeyDown("up")&&(onGround()==true))
{
vspeed = jumpHeight;
fall();
}
}
boolean onGround()
{
Actor under = getOneObjectAtOffset (0, getImage().getHeight()/2, Ground.class);
return under != null;
}
public void fall()
{
setLocation (getX(), getY() + vspeed);
vspeed = vspeed + vspeedplus;
}
public void checkFalling()
{
if(onGround()== false)
{
fall();
}
if(onGround()== true)
{
vspeed = 0;
}
if(getY() > 790)
{
setLocation(70,623);
}
}
}