Dawn/src/dawnrose/scene/components/entity/EntityHealth.cpp

40 lines
884 B
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "EntityHealth.hpp"
using namespace Dawn;
EntityHealth::EntityHealth(SceneItem* item) : SceneItemComponent(item) {
}
void EntityHealth::onStart() {
// Update
useEvent([&](float_t delta){
if(this->invincibleTime > 0.0f) {
this->invincibleTime -= delta;
}
if(this->stunTime > 0.0f) {
this->stunTime -= delta;
}
}, getScene()->eventSceneUpdate);
}
bool_t EntityHealth::isInvincible() {
return this->invincibleTime > 0.0f;
}
bool_t EntityHealth::isStunned() {
return this->stunTime > 0.0f;
}
void EntityHealth::damage(struct DamageInformation info) {
if(this->isInvincible()) return;
this->health -= info.amount;
this->invincibleTime = info.invincibleTime;
this->stunTime = info.stunTime;
}