Hello, I'm trying to create a bar of life with a big amount of health , I followed a tutorial on Youtube, the issue here is that I need "health" to be 4000, but if the value of health is greater than the width of the bar, it doesn't render it (using the same formula) I'll leave here the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and Mou seInfo) /** * Write a description of class HealthBar here. * * @author (your name) * @version (a version number or a date) */ public class HealthBar extends Actor { static int health = 4000 ; int healthBarWidth = 160 ; int healthBarHeight = 3 ; 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, healthBarHeight)); GreenfootImage healthbarim = getImage(); healthbarim.setColor(Color.RED); healthbarim.fillRect( 1 , 1 , health * pixelsPerHealthPoint, healthBarHeight); } public void loseHealth(){ health -= 1 ; } } |