What would be the best way to make a heath bar in greenfoot.


public ScoreBar bar2 = new ScoreBar("","Score",0, roundScore);
public Bar bar = new Bar("Heath","points",0, 100);
Bar scoreBar = new Bar("Score", "points", 0, roundscore); Bar healthBar = new Bar("Health", "points", 0, 100);
java.lang.ArithmeticException: / by zero at ScoreBar.newImage(ScoreBar.java:56) at ScoreBar.add(ScoreBar.java:110) at ScoreBar.<init>(ScoreBar.java:48) at Mw.<init>(Mw.java:13) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at greenfoot.core.Simulation.newInstance(Simulation.java:578) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:408) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465) at greenfoot.core.Simulation.maybePause(Simulation.java:279) at greenfoot.core.Simulation.runContent(Simulation.java:210) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.NullPointerException at greenfoot.World.addObject(World.java:392) at Mw.prepare(Mw.java:82) at Mw.<init>(Mw.java:33) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at greenfoot.core.Simulation.newInstance(Simulation.java:578) at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:408) at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465) at greenfoot.core.Simulation.maybePause(Simulation.java:279) at greenfoot.core.Simulation.runContent(Simulation.java:210) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:663) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:867) at All.canSee(All.java:47) at Player.checkCollision(Player.java:63) at Player.act(Player.java:35) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:663) at greenfoot.Actor.getOneObjectAtOffset(Actor.java:867) at All.canSee(All.java:47) at Player.checkCollision(Player.java:71) at Player.act(Player.java:35) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.ArithmeticException: / by zero at Bar.newImage(Bar.java:56) at Bar.add(Bar.java:110) at Bar.<init>(Bar.java:48) at Mw.<init>(Mw.java:13) at PlayGame.checkClick(PlayGame.java:24) at PlayGame.act(PlayGame.java:17) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.ArithmeticException: / by zero at Bar.newImage(Bar.java:56) at Bar.add(Bar.java:110) at Bar.<init>(Bar.java:48) at Mw.<init>(Mw.java:13) at PlayGame.checkClick(PlayGame.java:24) at PlayGame.act(PlayGame.java:17) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.ArithmeticException: / by zero at Bar.newImage(Bar.java:56) at Bar.add(Bar.java:110) at Bar.<init>(Bar.java:48) at Mw.<init>(Mw.java:13) at PlayGame.checkClick(PlayGame.java:24) at PlayGame.act(PlayGame.java:17) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.ArithmeticException: / by zero at Bar.newImage(Bar.java:56) at Bar.add(Bar.java:110) at Bar.<init>(Bar.java:48) at Mw.<init>(Mw.java:13) at PlayGame.checkClick(PlayGame.java:24) at PlayGame.act(PlayGame.java:17) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203) java.lang.ArithmeticException: / by zero at Bar.newImage(Bar.java:56) at Bar.add(Bar.java:110) at Bar.<init>(Bar.java:48) at Mw.<init>(Mw.java:13) at PlayGame.checkClick(PlayGame.java:24) at PlayGame.act(PlayGame.java:17) at greenfoot.core.Simulation.actActor(Simulation.java:565) at greenfoot.core.Simulation.runOneLoop(Simulation.java:523) at greenfoot.core.Simulation.runContent(Simulation.java:213) at greenfoot.core.Simulation.run(Simulation.java:203)
/** * Method 'newImage': builds a new image for the bar, determined by the values set for it */ private void newImage() { int barValue = (int) (barWidth * (value - minimumValue) / (maximumValue - minimumValue)); GreenfootImage leftImg = new GreenfootImage(referenceText + " ", (int) fontSize, textColor, backgroundColor); GreenfootImage rightImg = (showTextualUnits) ? new GreenfootImage(" " + value + " " + unitOfMeasure, (int) fontSize, textColor, backgroundColor) : new GreenfootImage(1, 1); int maxX = (leftImg.getWidth() > rightImg.getWidth()) ? leftImg.getWidth() : rightImg.getWidth(); GreenfootImage barImg = new GreenfootImage(barWidth + 4, barHeight + 4); barImg.setColor(backgroundColor); barImg.fill(); barImg.setColor(textColor); barImg.drawRect(0, 0, barImg.getWidth() - 1, barImg.getHeight() - 1); if (value > minimumValue) { if (breakLow) { if (value > (usingBreakValue ? breakValue : (int) (breakPercent * (maximumValue - minimumValue) / 100 + minimumValue))) barImg.setColor(safeColor); else barImg.setColor(dangerColor); } else { if (value < (usingBreakValue ? breakValue : (int) (breakPercent * (maximumValue - minimumValue) / 100 + minimumValue))) barImg.setColor(safeColor); else barImg.setColor(dangerColor); } if (value == (usingBreakValue ? breakValue : (int) (breakPercent * (maximumValue - minimumValue) / 100 + minimumValue))) { int r = (int) ((safeColor.getRed() + dangerColor.getRed()) / 2); int g = (int) ((safeColor.getGreen() + dangerColor.getGreen()) / 2); int b = (int) ((safeColor.getBlue() + dangerColor.getBlue()) / 2); barImg.setColor(new Color(r, g, b)); } barImg.fillRect(2, 2, barValue, barHeight); } int sumX = 2 * maxX + barImg.getWidth(); int maxY = 0; if (leftImg.getHeight() > maxY) maxY = leftImg.getHeight(); if (barImg.getHeight() > maxY) maxY = barImg.getHeight(); if (rightImg.getHeight() > maxY) maxY = rightImg.getHeight(); GreenfootImage image = new GreenfootImage(sumX, maxY); image.setColor(backgroundColor); image.fill(); image.drawImage(leftImg, maxX - leftImg.getWidth(), (image.getHeight() - leftImg.getHeight()) / 2); image.drawImage(barImg, maxX, (image.getHeight() - barImg.getHeight()) / 2); image.drawImage(rightImg, maxX + barImg.getWidth(), (image.getHeight() - rightImg.getHeight()) / 2); setImage(image); }