feat: player health status updates HUD
This commit is contained in:
parent
7b231bd0f3
commit
e6af6557e0
3 changed files with 17 additions and 0 deletions
|
|
@ -9,6 +9,7 @@ void HealthStatus::_bind_methods() {
|
|||
|
||||
ADD_SIGNAL(MethodInfo(sig_death));
|
||||
ADD_SIGNAL(MethodInfo(sig_health_changed, PropertyInfo(Variant::INT, "remaining"), PropertyInfo(Variant::INT, "delta")));
|
||||
ClassDB::bind_method(D_METHOD("get_max_health"), &self_type::get_max_health);
|
||||
}
|
||||
|
||||
void HealthStatus::ready() {
|
||||
|
|
@ -30,12 +31,20 @@ void HealthStatus::_notification(int what) {
|
|||
|
||||
void HealthStatus::set_health(int value) {
|
||||
this->health = value;
|
||||
if (!is_ready() || Engine::get_singleton()->is_editor_hint()) {
|
||||
// if setting health as serialized, set max_health as well
|
||||
this->max_health = value;
|
||||
}
|
||||
}
|
||||
|
||||
int HealthStatus::get_health() const {
|
||||
return this->health;
|
||||
}
|
||||
|
||||
int HealthStatus::get_max_health() const {
|
||||
return this->max_health;
|
||||
}
|
||||
|
||||
void HealthStatus::damage(int amount) {
|
||||
if (this->health > 0) {
|
||||
amount = Math::abs(amount);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ protected:
|
|||
public:
|
||||
void set_health(int health);
|
||||
int get_health() const;
|
||||
int get_max_health() const;
|
||||
|
||||
void damage(int amount);
|
||||
void heal(int amount);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue