# Java heart based health mechanic

so I've made a basic game in java w/ LWJGL 2 and Slick. Right now Im working on the hud and health system. I'm kindof trying to get a minecraft like health system, 15 hearts for health,but I want the health to change from level to level. Right now Ive got this:

    int z = (int) (Math.floor(hp/15)); // this is how many hearts are being drawn
for(int k = 0; k < z; k++){
if(z >= 15){
z = 15; // here it says that it can't draw more than 15 hearts
}
g.drawImage(heart, x + k * 32, y); // it draws the hearts with some distance inbetween each heart
}


I'd be happy if I get some suggestions on how could I add half a heart "mechanic", like if I have 30 max health and 15 hearts (allthought rightnow I have 200 hp, I wanna work with bigger numbers :P) that would mean that If I had 15 health it should draw 7 full hearts and 1 half heart. I don't exactly know how to do that. If you can please do help :D. Thank you

## 1 Answer

You could try something like this

    int hp = 15;

for(int i = 0; i < hp/2; i++)
System.out.println("Heart");
if(hp % 2 == 1)
System.out.println("Half Heart");


Just replace the print calls with your graphics calls.