Skip to content

Commit

Permalink
Add health gauge showing excess health #71
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Jan 1, 2024
1 parent 04d6b94 commit fa53088
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/cdogs/hud/health_gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void HealthGaugeDraw(
}

HSV hsv = {0.0, 1.0, 1.0};
const int maxHealth = ActorGetCharacter(actor)->maxHealth;
const int maxHealth = ActorGetMaxHeal(actor, false);
const int health = MIN(actor->health, maxHealth);
if (actor->poisoned)
{
Expand Down Expand Up @@ -110,6 +110,20 @@ void HealthGaugeDraw(
barColor.a = opts.Mask.a;
HUDDrawGaugeInner(device, &gPicManager, pos, innerWidth, barColor);

// Draw a second bar if health is over max
if (actor->health > maxHealth)
{
const int healthOverMax = actor->health - maxHealth;
const int excessHealth = ActorGetMaxHeal(actor, true);
const int excessHealthRange = MAX(excessHealth - maxHealth, healthOverMax);
const int innerWidth = MAX(1, width * healthOverMax / excessHealthRange);
hsv.h = 120.0;
hsv.v = 1.0;
barColor = ColorTint(colorWhite, hsv);
barColor.a = opts.Mask.a;
HUDDrawGaugeInner(device, &gPicManager, pos, innerWidth, barColor);
}

// Draw health number label
char s[50];
sprintf(s, "%d", actor->health);
Expand Down

0 comments on commit fa53088

Please sign in to comment.