int num = 19 -hp;
hpbar hpbar = (hpbar) getWorld().getObjects(hpbar.class).get(0);
hpbar.setImage(num+".gif");
int num = 19 -hp;
hpbar hpbar = (hpbar) getWorld().getObjects(hpbar.class).get(0);
hpbar.setImage(num+".gif");import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
public class protag extends Actor
{
int powercount = 0;
int ammo = 3;
int hp = 18;
GifImage gifImage = new GifImage("char 1.gif");
int speed = 3;
public void destroyEnemies()
{
//"Enemy" can be any class that you want the bullet to destroy.
Actor enemy = getOneIntersectingObject(tree.class);
if(enemy != null) {
getWorld().removeObject(enemy);
getWorld().removeObject(this);
}
}
public void checkFire()
{
if(Greenfoot.isKeyDown("space")) {
ammo = ammo - 1;
if(ammo <= 0){
ammo = 3;
}
}
}
public void controls()
{
int speed = 3;
if(Greenfoot.isKeyDown("a")){
setLocation(getX() - speed, getY());
getWorld().removeObjects(getWorld().getObjects(hpbar.class));
getWorld().addObject(new hpbar(), getX() - speed, getY() + 45);
}
if(Greenfoot.isKeyDown("d")){
setLocation(getX() + speed, getY());
getWorld().removeObjects(getWorld().getObjects(hpbar.class));
getWorld().addObject(new hpbar(), getX()+speed, getY() + 45);
}
}
public void act()
{
int num = 19 -hp;
hpbar hpbar = (hpbar) getWorld().getObjects(hpbar.class).get(0);
hpbar.setImage(num+".gif");
controls();
setImage(gifImage.getCurrentImage());
checkFire();
destroyEnemies();
if(hp<=0){
World W = getWorld();
W.removeObject(this);
W.removeObjects(W.getObjects(hpbar.class));
return;
}
if(isTouching(bomb.class)){
hp = hp - 1;
Actor bomb = getOneIntersectingObject(bomb.class);
getWorld().removeObject(bomb);
}
}
}