Skip to content

Commit

Permalink
feat: health bar now changes colour based on health (green to red)
Browse files Browse the repository at this point in the history
  • Loading branch information
Notexe committed Feb 19, 2024
1 parent 2b2a93d commit ec1f9cd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Binary file modified content/chunk0/scaleform/001D0947392E2DD6.GFXF
Binary file not shown.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "Simple Health Bar",
"description": "Adds a simple health bar to the left of the minimap.",
"authors": ["Notex"],
"contentFolders": ["content"],
"frameworkVersion": "2.33.7",
"updateCheck": "https://github.com/Notexe/h3-simple-health-bar/releases/latest/download/updates.json"
}
Binary file modified source/bin/HealthBar.swf
Binary file not shown.
24 changes: 21 additions & 3 deletions source/src/healthbar/HealthBar.as
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package healthbar {
import common.BaseControl;

import flash.geom.ColorTransform;

public class HealthBar extends BaseControl {

private var m_healthBarView:HealthBarView = new HealthBarView();
Expand All @@ -19,12 +21,28 @@ public class HealthBar extends BaseControl {
public function UpdateHealth():void {
var m_maxHealth:Number = 100;
m_healthBarView.HealthBarInner.scaleY = m_currentHealth / m_maxHealth;
UpdateHealthBarColour();
}

private function UpdateHealthBarColour():void {
var m_maxHealth:Number = 100;
var healthRatio:Number = m_currentHealth / m_maxHealth;
var m_fullHealthGreen:uint = 0x00BA00;
var m_lowHealthRed:uint = 0xFA0000;
var red:uint = interpolate((m_lowHealthRed >> 16) & 0xFF, (m_fullHealthGreen >> 16) & 0xFF, healthRatio);
var green:uint = interpolate((m_lowHealthRed >> 8) & 0xFF, (m_fullHealthGreen >> 8) & 0xFF, healthRatio);
var blue:uint = interpolate(m_lowHealthRed & 0xFF, m_fullHealthGreen & 0xFF, healthRatio);
var colorTransform:ColorTransform = new ColorTransform();
colorTransform.color = (red << 16) | (green << 8) | blue;
m_healthBarView.HealthBarInner.transform.colorTransform = colorTransform;
}

private function interpolate(start:uint, end:uint, ratio:Number):uint {
return start + (end - start) * ratio;
}

public function set Debug(health:Number):void {
m_currentHealth = health;
m_healthBarView.HealthBarText.text = String(Math.round(health));
UpdateHealth();
SetHealth(health);
}

}
Expand Down

0 comments on commit ec1f9cd

Please sign in to comment.