HealthBar

Node for generic health bar.

Inherits : Node2D

Signals

dead
Signal emitted when the health bar reach 0.

Emitted by : damage() Received by : Ennemy._on_HealthBar_dead(), Player._on_HealthBar_dead()

Description

This is a general-purpose Node, implementing a neat health bar.

It has really basic behavior for now, no regeneration or stuff like this.

Behaviors handled so far :

  • Possible to set the color of the health bar (the shadow is always set to orange).
  • Change the maximum number of HP.
  • Take damages.
  • Heal HP.

Methods description

init(max_health, color=Color(168, 0, 0))

Arguments

max_health
Maximum HP for this health bar.
color
Color of the health bar.
Defaults to red (code RGB : 168, 0, 0)

Method used to setup the health bar, with a specific number of maximum HP and specific color for the health bar.

set_health(h)

Arguments

h
New number of HP.
Set the current number of HP to a specific number.
This method should be used (and not manually change the property of the Node) in order to keep the animation clean.

set_max_health(h)

Arguments

h
New number of maximum HP.

Set the maximum number of HP to a specific number.

damage(d)

Arguments

d
Amount of damage to inflict.
This method update the health bar based on the amount of damage inflicted.
If the number of HP reach 0, it emits the dead signal.

Emitted signals

dead
This signal is emitted when the health bar reach 0 HP.

heal(h)

Arguments

h
Amount of damage to heal.
This method update the health bar based on the amount of damage healed.
Literally the opposite of the damage() function.