Hey guys, I'm making a character design screen for a game I'm working on and one of the UI elements is a health bar that should update depending on the values in one of its superclasses; so far the healthbar is capable of sliding up and down dependant on the value given to it from the world constructor, but I really don't want it to take the integer I want it to display from the constructor to make life in the future easier. Whenever I set the value to anything above 100, it instantly starts dropping to 0 (unintended) and whenever I set the value to 100 or below the bar doesn't change the display.
Here's the line in the World constructor that builds the healthbar:
Here's my code for the health bar:
Here's my code for the CellStats superclass:
Tell me where I'm being a complete noob, and how I can get the value in currentHealth to dynamically update the bar.
ProgBar health = new ProgBar(100, 300, 20, "Health", 90, 240, 7);
public class ProgBar extends CellStats
{
public int curVar;
public int barWidth;
public int barHeight;
public int pxPerHealthPoint;
public String barLabel;
public int RED;
public int GREEN;
public int BLUE;
public ProgBar(int Fraction, int Width, int Height, String barLbl, int r, int g, int b)
{
curVar = Fraction;
barWidth = Width;
barHeight = Height;
barLabel = barLbl;
RED = r;
GREEN = g;
BLUE = b;
pxPerHealthPoint = (int)barWidth/curVar;
updateBar();
}
public void act()
{
updateBar();
}
public void updateBar()
{
//draws the progress bar
setImage(new GreenfootImage(160+ (barWidth + 4), barHeight + 4));
GreenfootImage barBg = getImage();
barBg.setColor(new Color (100, 100, 100));
barBg.fillRect(160, 0, barWidth + 4, barHeight + 4);
barBg.setColor(new Color(RED, GREEN, BLUE));
barBg.fillRect(162, 2, curVar*pxPerHealthPoint, barHeight);
barBg.setFont(barBg.getFont().deriveFont(20f));
barBg.setColor(new Color(255, 255, 255));
barBg.drawString(barLabel, 1, 20);
barBg.drawString(String.valueOf(curVar), 425, 19);
int currentHealth = CellStats.returnValues();
if(currentHealth > curVar && curVar > 0)
{
loseValue();
}
}
public void gainValue()
{
curVar++;
}
public void loseValue()
{
curVar--;
}
}public class CellStats extends Actor
{
static int currentHealth = 100;
int baseHealth = 100;
int heatRes = 0;
int coldRes = 0;
int shield = 0;
int atpCap = 300;
int atpStored = 0;
public CellStats()
{
returnValues();
}
public static int returnValues()
{
return currentHealth;
}


