break-utopia/modules/break_utopia/damage_box.cpp

27 lines
589 B
C++

#include "damage_box.h"
#include "break_utopia/hit_box.h"
#include "break_utopia/macros.h"
#include "core/config/engine.h"
void DamageBox::_bind_methods() {
BIND_PROPERTY(Variant::INT, damage);
}
void DamageBox::on_body_entered(Node *node) {
if (HitBox * hit{ cast_to<HitBox>(node) }) {
hit->damage(this->damage);
}
}
void DamageBox::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (what) {
default:
return;
case NOTIFICATION_READY:
connect("body_entered", callable_mp(this, &self_type::on_body_entered));
return;
}
}