break-utopia/modules/break_utopia/damage_box.cpp

51 lines
1.1 KiB
C++

#include "damage_box.h"
#include "break_utopia/hit_box.h"
#include "break_utopia/macros.h"
#include "break_utopia/player_body.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;
}
}
void EnemyDamageBox::_bind_methods() {
BIND_PROPERTY(Variant::FLOAT, damage);
}
void EnemyDamageBox::on_body_entered(Node *node) {
if (PlayerBody * player{ cast_to<PlayerBody>(node) }) {
player->deal_damage(damage);
}
}
void EnemyDamageBox::_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;
}
}