Hi evryone!
I have a problem 1 week now and I don’t know what I am doing wrong. I’m making a small pixel game with some help. I was making a health-system, but I made the code and it just didnt worked. You can see why on the picture:
http://img819.imageshack.us/img819/5408/9kb2.png
QWE has 15 HP and the healthbar is empty,
ZA has 16 HP and the healthbar is full.
the code I used:
if (HUDSHOWN >= 2){
for(int i = 0; i <= modifier*2; i++){
int manaColour = -1;
int healthColour = -1;
int mMax = 0;
int hMax = 0;
if(mana != 0 && maxMana != 0) mMax = mana/maxMana*16;
if(health != 0 && maxHealth != 0) hMax = health/maxHealth*16;
if(i > 0 && i < modifier*2){
if(i - 1 < hMax){
healthColour = 500;
}
if(i - 1 < mMax){
manaColour = 115;
}
} else if(i == 0 || i == modifier*2){
healthColour = 0;
manaColour = 0;
}
int healthBarColour= Colours.get(-1, healthColour, manaColour, 000);
screen.render(xOffset-2 + i, yOffset - 6, 1 + 27 * 32, healthBarColour, 0x00, scale);
}
}
Explain of the code:
The images are on a spritesheet and I can change the colours of the images. So I made a single healthbar piece that looks like 4 pixels above each other:
Pixel 1: [Always black (000)]
Pixel 2: [manaColour]
Pixel 3: [healthColour]
Pixel 4: [Always black (000)]
So at the borders I set mana and healthColour to 000. But in the middle I set the to how much health there is. Only hMax and mMax aren’t working. It’s probably because I made a little mistake or something. But I hope someone can explain it without saiying the code (Because I need to learn Java, not copying it).
[EDIT]:
Sorry placed the wrong code, it’s this one:
if (HUDSHOWN >= 2){
for(int i = 0; i <= modifier*2; i++){
int manaColour = -1;
int healthColour = -1;
int mMax = 0;
int hMax = 0;
if(mana != 0 && maxMana != 0) mMax = mana/maxMana*16;
if(health != 0 && maxHealth != 0) hMax = health/maxHealth*16;
if(i > 0 && i < modifier*2){
for(int ih = i - 1; ih < hMax; ih++){
healthColour = 500;
}
for(int im = i - 1; im < mMax; im++){
manaColour = 115;
}
} else if(i == 0 || i == modifier*2){
healthColour = 0;
manaColour = 0;
}
int healthBarColour= Colours.get(-1, healthColour, manaColour, 000);
screen.render(xOffset-2 + i, yOffset - 6, 1 + 27 * 32, healthBarColour, 0x00, scale);
}
}
Thanks!
-RoseSlayer