Skip to content

Commit

Permalink
adding animations to health bar
Browse files Browse the repository at this point in the history
  • Loading branch information
frodare committed Sep 19, 2018
1 parent 0f8d983 commit 1bcec63
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/main/java/net/torocraft/torohud/display/BarDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,40 @@ public void renderBossHealth() {
mc.fontRenderer.drawStringWithShadow(name + " " + health + "", barX, y + 2, 16777215);
}

private static final float HEALTH_INDICATOR_DELAY = 45;
private float previousHealth = -1;
private float previousHealthDelay = HEALTH_INDICATOR_DELAY;

private void renderHealthBar() {

if (previousHealth == entity.getHealth() || previousHealth == -1) {
previousHealthDelay = HEALTH_INDICATOR_DELAY;
previousHealth = entity.getHealth();
} else if (previousHealthDelay > 0) {
previousHealthDelay--;
} else if (previousHealthDelay < 1 && previousHealth > entity.getHealth()) {
previousHealth -= 0.1f;
} else {
previousHealth = entity.getHealth();
previousHealthDelay = HEALTH_INDICATOR_DELAY;
}

Color color = determineColor();
float percent = entity.getHealth() / entity.getMaxHealth();
float percent2 = previousHealth / entity.getMaxHealth();

renderBarBacker(color);
renderBar(Color.YELLOW, percent2);
renderBar(color, percent);
}

private void renderBarBacker(Color color) {
gui.drawTexturedModalRect(barX, barY, 0, color.ordinal() * 5 * 2, BAR_WIDTH, 5);
}

private void renderBar(Color color, float percent) {
int healthWidth = (int) (percent * BAR_WIDTH);
if (healthWidth > 0) {
gui.drawTexturedModalRect(barX, barY, 0, Color.YELLOW.ordinal() * 5 * 2 + 5, healthWidth + 4, 5);
gui.drawTexturedModalRect(barX, barY, 0, color.ordinal() * 5 * 2 + 5, healthWidth, 5);
}
}
Expand Down

0 comments on commit 1bcec63

Please sign in to comment.