Guys i need some answers on how to apply the healthbar classes to my shooting game i've downloaded and viewed all scenarios but still can't apply it
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class K here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class K extends ShooterActors
{
/**
* Act - do whatever the K wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int fspeed = 0;
private int acceleration = 2;
private int speed =5;
boolean CanJump;
KiBlast kiblast = new KiBlast();
private int points = 0;
private Bar healthBar;
public void act()
{
movement();
if(isOnGround()){
CanJump = true;
} else{
CanJump = false;
fall();
}
fire();
shoot();
}
public K()
{
healthBar = new Bar("", "", 100, 100);
healthBar.setShowTextualUnits(false);
healthBar.setBarWidth(30);
healthBar.setBarHeight(3);
}
public boolean isOnGround()
{
Cl Window = (Cl) getWorld();
if(getY() + (getImage().getHeight() / 2) >= (Window.getHeight() -1)) {
return true;
}
return false;
{ healthBar.setLocation(getX(), getY()-30);
if (healthBar.getValue() == 0) getWorld().removeObect(this); }
}
public void jump()
{
fspeed = -10;
fall();
}
public void fall()
{
setLocation ( getX(), getY() + fspeed);
fspeed = fspeed + acceleration;
}
public void movement()
{
if(Greenfoot.isKeyDown("left"))
{
MoveLeft();
}
if(Greenfoot.isKeyDown("right"))
{
MoveRight();
}
if(Greenfoot.isKeyDown("up"))
{
jump();
}
}
public void MoveLeft()
{
setLocation (getX() - speed, getY());
}
public void MoveRight()
{
setLocation (getX() + speed, getY());
}
public void fire()
{
if(Greenfoot.isKeyDown("x"))
{
World world = getWorld();
world.addObject(kiblast, 0, 0);
kiblast.setLocation(getX(),getY());
}
}
public void shoot()
{
{
if ("c".equals(Greenfoot.getKey()))
getWorld().addObject(new KiBlast(), getX(), getY());
points = points+5;
}
}
protected void addedToWorld(World world)
{
world.addObject(healthBar, getX(), getY()-30);
}
}