Rendering Health-System like Zelda or MineCraft?

Hello there,

Currently I’m working on a small RPG game, but in a RPG game you need health. So I started to begin with coding the health system. The only part that´s still missing is the part of rendering them. The part that I already finished is that you have total 12 hp (in half heart so 6 hp total) and the damage system.

Idea
My idea was to make “half” hearts, this aren’t really half hearts but just the same heart image with other color.
If you have as example 7 hp (3,5 hearts total) But how can you code the rendering of this idea?

I don’t want the full code, give me some hints/tips how I can do this. I still need too learn alot.
-RoseSlayer

eeeh sure, well its kinda different if you use opengl directly or a lib or java2d…

I would just make textures for all the hearts. That’s just my lazy side talking though, I’m sure there’s a way to actually do it with code. It would probably be much harder than just texturing hearts for every possibility though. Maybe someone else has a suggestion?

@opiop65,
I want to save as much space in my spritesheet as possible, so not the greatest option.

@Cero,
I’m using eclipse with java jdk1.7_0 (maybe jdk1.6_0) only so nothing else then that.

-RoseSlayer

It’s really easy:


int numberOfFilledHearts = hp / 2; // <- This HAS to be an Integer!
boolean extraHalfHeart = hp % 2 == 1;

int i = 0;
for (; i < numberOfFilledHearts; i++) {
    drawFilledHeart(x + i*heartWidth, y);
}
if (extraHalfheart)
    drawHalfHeart(x + i*heartWidth, y);
}

That’s it.
(btw, the % operator is modulo modulo = remainder of division. So i % 2 == 0 for example checks, whether the number is a round number)

@matheus23,

I will try the code out, but already thanks for helping me out!

-RoseSlayer