hi and one can help me make my hp bar work please i need it for my school project urgent need it work by next monday
any one can help me please email me at nic555ex3@gmail.com i will sent u my files


import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Mushroom here. * * @author (your name) * @version (a version number or a date) */ public class Tojan extends BadGuys { boolean EatPlayer = false; int frame = 0; private int animationCount; private int vSpeed = 0; private int acceleration = 1; private int speed = 2; private int spriteHeight = getImage().getHeight(); private int spriteWidth = getImage().getWidth(); private int lookForGroundDistance = (int)spriteHeight/2; private int lookForEdge = (int)spriteWidth/2; GreenfootImage Mush1l = new GreenfootImage("Mush1l.png"); GreenfootImage Mush2l = new GreenfootImage("Mush2l.png"); GreenfootImage Mush3l = new GreenfootImage("Mush3l.png"); GreenfootImage Mush4l = new GreenfootImage("Mush4l.png"); GreenfootImage Mush5l = new GreenfootImage("Mush5l.png"); GreenfootImage Mush1r = new GreenfootImage("Mush1r.png"); GreenfootImage Mush2r = new GreenfootImage("Mush2r.png"); GreenfootImage Mush3r = new GreenfootImage("Mush3r.png"); GreenfootImage Mush4r = new GreenfootImage("Mush4r.png"); GreenfootImage Mush5r = new GreenfootImage("Mush5r.png"); /** * Act - do whatever the Mush wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { checkFall(); move(); checkRightWalls(); checkLeftWalls(); checkEdge(); animationCount ++; tryToEatPlayer(); if(speed<0) { if(animationCount % 4 == 0) // Slows down animation animateLeft(); } else { if(animationCount % 4 == 0) // Slows down animation animateRight(); } } public void animateLeft() { if(frame == 0) { setImage(Mush1l); } if(frame == 1) { setImage(Mush2l); } if(frame == 2) { setImage(Mush3l); } if(frame == 3) { setImage(Mush4l); } if(frame == 4) { setImage(Mush5l); frame = 0; } frame++; } public void animateRight() { if(frame == 0) { setImage(Mush1r); } if(frame == 1) { setImage(Mush2r); } if(frame == 2) { setImage(Mush3r); } if(frame == 3) { setImage(Mush4r); } if(frame == 4) { setImage(Mush5r); frame = 0; } frame++; } public void checkEdge() { if(getX() < 10 || getX() > getWorld().getWidth() - 10) { speed *= -1; } } public void move() { Actor ground = getOneObjectAtOffset(lookForEdge, lookForGroundDistance, Platform.class); if(ground == null) { speed *= -1; // Reverse direction lookForEdge *= -1; // Looks for a negative number } else { move(speed); } } public void fall() { setLocation(getX(), getY() + vSpeed); if(vSpeed <=9) { vSpeed = vSpeed + acceleration; } } public boolean onGround() { int spriteHeight = getImage().getHeight(); int yDistance = (int)(spriteHeight/2) + 5; Actor ground = getOneObjectAtOffset(0, getImage().getHeight()/2, Platform.class); if(ground == null) { return false; } else { moveToGround(ground); return true; } } public void moveToGround(Actor ground) { int groundHeight = ground.getImage().getHeight(); int newY = ground.getY() - (groundHeight + getImage().getHeight())/2; setLocation(getX(), newY); } public void checkFall() { if(onGround()) { vSpeed = 0; } else { fall(); } } public boolean checkRightWalls() { int spriteWidth = getImage().getWidth(); int xDistance = (int)(spriteWidth/2); Actor rightWall = getOneObjectAtOffset(xDistance, 0, Platform.class); if(rightWall == null) { return false; } else { stopByRightWall(rightWall); return true; } } public void stopByRightWall(Actor rightWall) { int wallWidth = rightWall.getImage().getWidth(); int newX = rightWall.getX() - (wallWidth + getImage().getWidth())/2; setLocation(newX - 5, getY()); speed *= -1; } public boolean checkLeftWalls() { int spriteWidth = getImage().getWidth(); int xDistance = (int)(spriteWidth/-2); Actor leftWall = getOneObjectAtOffset(xDistance, 0, Platform.class); if(leftWall == null) { return false; } else { stopByLeftWall(leftWall); return true; } } public void stopByLeftWall(Actor leftWall) { int wallWidth = leftWall.getImage().getWidth(); int newX = leftWall.getX() + (wallWidth + getImage().getWidth())/2; setLocation(newX + 5, getY()); speed *= -1; } /** * Return true if we can see an object of class 'clss' right where we are. * False if there is no such object here. */ public boolean canSee(Class clss) { Actor actor = getOneObjectAtOffset(1, 1, clss); return actor != null; } /** * Try to grab an object of class 'clss'. This is only successful if there * is such an object where we currently are. Otherwise this method does * nothing. */ public void eat(Class clss) { Actor actor = getOneObjectAtOffset(1, 1, clss); if(actor != null) { World myWorld = getWorld(); Level01 level01 = (Level01)myWorld; HealthBar healthbar = level01.getHealthBar(); if(EatPlayer == false) { HealthBar.loseHealth(); eatPlayer = true; if(healthbar.health <=0) getWorld().removeObject(actor); } } } public void tryToEatPlayer() { if (canSee(Player.class)) { eat(Player); Greenfoot.setWorld(new gameover()); } } }
mport greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; public class HealthBar extends Actor { int health = 4; int healthBarWidth = 80; int healthBarHeight = 15; int pixelsPerHealthPoint =(int)healthBarWidth/health; /** * Act - do whatever the HealthBar wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public HealthBar() { update(); } public void act() { update(); } public void update() { setImage(new GreenfootImage(healthBarWidth + 2, healthBarHeight + 2)); GreenfootImage myImage = getImage(); myImage.setColor(Color.WHITE); myImage.drawRect(0, 0, healthBarWidth + 1, healthBarHeight + 1); myImage.setColor(Color.RED); myImage.fillRect(1, 1, health*pixelsPerHealthPoint, healthBarHeight); } public void loseHealth() { health--; } }