the health bar works on my actor but the color is still green even though i got hit many times


public void hit() { Actor heartlessblast = getOneIntersectingObject(HeartlessBlast.class); if(heartlessblast != null) { Health = Health - 10; getWorld().removeObject(heartlessblast); World world = getWorld(); Cl cl = (Cl)world; Bar bar = cl.getBar(); bar.setBreakValue(brkVal); }
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 int Health = 100; public static int MaxHealth = 100; public int brkVal = 10; public void act() { movement(); if(isOnGround()){ CanJump = true; } else{ CanJump = false; fall(); } fire(); shoot(); healthBar.setLocation(getX(), getY()-30); if (healthBar.getValue() == 0){ getWorld().removeObject(healthBar); getWorld().removeObject(this); } hit(); } 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; } 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); } public void hit() { Actor heartlessblast = getOneIntersectingObject(HeartlessBlast.class); if(heartlessblast != null) { Health = Health - 10; getWorld().removeObject(heartlessblast); World world = getWorld(); Cl cl = (Cl)world; Bar bar = cl.getBar(); bar.setBreakValue(brkVal); } if(Health <= 0) { Actor bar = getOneIntersectingObject(Bar.class); getWorld().removeObject(bar); getWorld().removeObject(this); } } }
healthBar.setBreakValue(10);
healthBar.subtract(10);
if(Health <= 0) { getWorld().removeObject(healthBar); getWorld().removeObject(this); }