import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Player here.
*
* @author ( )
* @version ( 1.0 3/2/17 )
*/
public class Player extends Actor
{
public void act()
{
keyControlmove();
}
/**
* Create a player and initialize its images
*/
public Player()
{
* (this is an error IDK why ->)player = new GreenfootImage("heroClassStanding.png");
* this.setImage(playerImg);
}
/**
*
*/
public void walkLeft(int distance)
{
this.walk(distance, -10, "HeroWalk.png", "HeroWalk2.png");
}
/**
* Walk a bit to the right. 'distance' determines how far to walk. Use small numbers (1 to 10).
*/
public void walkRight(int distance)
{
this.walk(distance, 10, "HeroWalk.png", "HeroWalk2.png");
}
/**
* Jump up. 'distance' determines how high to jump. Use small numbers (1 to 10).
*/
public void jumpUp(int distance)
{
this.jump(distance, -10, "small-cat-fly.png","small-cat-fly-2.png");
}
/**
* Jump down. 'distance' determines how far down to jump. Use small numbers (1 to 10).
*/
public void jumpDown(int distance)
{
this.jump(distance, 10, "small-cat-fly.png","small-cat-fly-2.png");
}
/**
* Internal walk method. Walk a given distance into a given direction, using given images.
*/
private void walk(int distance, int direction, String img1, String img2)
{
for (int i = 0; i < distance; i++)
{
super.setImage(img1);
this.wait(4);
super.setLocation(super.getX( ) + direction, super.getY());
super.setImage(img2);
this.wait(4);
super.setLocation(super.getX() + direction, super.getY());
}
}
/**
* Internal jump method. Jump a given distance into a given direction, using given images.
*/
private void jump(int distance, int direction, String img1, String img2)
{
for (int i = 0; i < distance; i++)
{
super.setImage(img1);
this.wait(4);
super.setLocation(super.getX( ) , super.getY()+ direction);
super.setImage(img2);
this.wait(4);
super.setLocation(super.getX( )+ direction , super.getY());
}
}
//Arrow Keys
public void keyControlmove()
{
if(Greenfoot.isKeyDown("w"))
{
jumpUp(2);
}
if(Greenfoot.isKeyDown("A"))
{
move(-2);
}
if(Greenfoot.isKeyDown("D"))
{
move(2);
}
}
}

