/**
* Write a description of class Pxl1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Pxl1 extends Actor
{
HealthBar healthbar = new HealthBar();
private int vSpeed = 0;
private int acceleration = 1;
private int jumpHeight= - 8;
Fire fire = new Fire();
/**
* Act - do whatever the Pxl1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
movement();
saca();
checkFall();
pictures();
fireball();
hitByFire();
}
/**
* This method lets the character move
*/
public void movement()
{
int y = getY();
int x = getX();
if(Greenfoot.isKeyDown("d"))
{
move(5);
setImage("move_forward.png");
}
if(Greenfoot.isKeyDown("a"))
{
move(-5);
setImage("move.png");
}
else
{
setImage("Fighter-1.png");
}
if(Greenfoot.isKeyDown("w"))
{
jump();
}
if(Greenfoot.isKeyDown("f"))
{
move(30);
}
if(Greenfoot.isKeyDown("tab"))
{
move(-30);
}
}
public void pictures()
{
if(Greenfoot.isKeyDown("e"))
{
setImage("Fighter-punch.png");
}
else
{
setImage("Fighter-1.png");
}
if(Greenfoot.isKeyDown("q"))
{
setImage("Fighter-kicking.png");
}
if(Greenfoot.isKeyDown("a"))
{
setImage("move.png");
}
if(Greenfoot.isKeyDown("d"))
{
setImage("move_forward.png");
}
}
/**
* makes the character jump
*/public void jump()
{
vSpeed= -5;
gravity();
}
/**
* makes the character fall
*/
public void checkFall()
{
if(onGround())
{
vSpeed = 0;
}
else
{
gravity();
}
}
/**
* makes the fall look real
*/
private void gravity()
{
setLocation(getX(), getY() +vSpeed);
vSpeed = vSpeed + acceleration;
}
/**
* makes the character land on the ground
*/
public boolean onGround()
{
Actor under = getOneObjectAtOffset(0,getImage().getHeight()/2,Ground.class);
return under != null;
}
public void fireball()
{
if (Greenfoot.isKeyDown("r"))
{
setImage("Fighter-punch.png");
World MyWorld = getWorld();
MyWorld.addObject(fire, 0, 0);
fire.setLocation(getX(), getY());
fire.setRotation(getRotation());
}
}
public void load()
{
if(isTouching(Load.class))
{
removeTouching(Load.class);
}
}
public void saca()
{
if(Greenfoot.isKeyDown("enter"))
{
load();
}
}
public void hitByFire()
{
Actor Ball2 = getOneObjectAtOffset(0, 0, Ball2.class);
if(Ball2 != null)
{
//World world = getWorld();
MyWorld myWorld = (MyWorld)getWorld();
HealthBar healthBar = myWorld.getHealthBar();
healthBar.loseHealth();
}
}
}