Hello, I have a "Savior" class that loses health if it comes into contact with a "Rocket" object. I want to display the amount of health in the bottom left corner of my world. Which is (600,400,1). Here is the code for my actor Savior
Would I need to have this number display be its own subclass of actor? I initially thought of having the display in my savior class, so I can reference the health variable.
public void act()
{
if(Greenfoot.isKeyDown("a")){
move(-3);
}
if(Greenfoot.isKeyDown("d")) {
move(3);
}
if(time > 0){
time--;
}
if(Greenfoot.isKeyDown("w")) {
if(time == 0){
getWorld().addObject(new Missile(), this.getX(), this.getY());
time = 30;
}
}
Hit();
}
public void Hit()
{
if (isTouching(Rocket.class)) {
removeTouching(Rocket.class);
health = health - 25;
if (health == 0) {
getWorld().removeObject(this);
}
}
}
public int getHealth() {
return health;
}
}
