feat: player health status updates HUD

This commit is contained in:
Sara 2025-08-31 14:07:03 +02:00
parent 7b231bd0f3
commit e6af6557e0
3 changed files with 17 additions and 0 deletions

View file

@ -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);