diff --git a/src/enemy.cpp b/src/enemy.cpp index c4257e7..dbfc8bd 100644 --- a/src/enemy.cpp +++ b/src/enemy.cpp @@ -10,6 +10,8 @@ namespace godot { void Enemy::_bind_methods() { #define CLASSNAME Enemy GDFUNCTION_ARGS(body_entered_vision_area, "body"); + GDFUNCTION_ARGS(on_death, "damage"); + GDFUNCTION_ARGS(on_damage, "damage", "remaining"); } void Enemy::_ready() { GDGAMEONLY(); @@ -18,6 +20,8 @@ void Enemy::_ready() { GDGAMEONLY(); this->vision_area = this->get_node("VisionArea"); this->vision_area->connect("body_entered", Callable(this, "body_entered_vision_area")); this->update_navigation_target(); + this->health->connect("death", Callable(this, "on_death")); + this->health->connect("damage", Callable(this, "on_damage")); } void Enemy::_process(double delta_time) { GDGAMEONLY(); @@ -57,6 +61,13 @@ void Enemy::update_navigation_target() { this->nav_agent->set_target_position(this->target_player->get_global_position()); } +void Enemy::on_damage(int delta, int health_left) { +} + +void Enemy::on_death(int delta) { + this->queue_free(); +} + Health *Enemy::get_health() { return this->health; } diff --git a/src/enemy.hpp b/src/enemy.hpp index 1c644f3..af23bbb 100644 --- a/src/enemy.hpp +++ b/src/enemy.hpp @@ -22,6 +22,9 @@ public: void update_navigation_target(); + void on_damage(int delta, int health_left); + void on_death(int damage); + virtual Health *get_health() override; virtual Health const *get_health() const override; diff --git a/src/health.cpp b/src/health.cpp index 7839d88..baea251 100644 --- a/src/health.cpp +++ b/src/health.cpp @@ -8,10 +8,10 @@ namespace godot { void Health::_bind_methods() { #define CLASSNAME Health GDPROPERTY(max_health, Variant::INT); - ClassDB::add_signal("Health", MethodInfo("damage", PropertyInfo(Variant::INT, "delta"), PropertyInfo(Variant::INT, "remaining"))); - ClassDB::add_signal("Health", MethodInfo("heal", PropertyInfo(Variant::INT, "delta"), PropertyInfo(Variant::INT, "remaining"))); - ClassDB::add_signal("Health", MethodInfo("health_changed", PropertyInfo(Variant::INT, "delta"), PropertyInfo(Variant::INT, "remaining"))); - ClassDB::add_signal("Health", MethodInfo("death", PropertyInfo(Variant::INT, "delta"))); + GDSIGNAL("damage", PropertyInfo(Variant::INT, "delta"), PropertyInfo(Variant::INT, "remaining")); + GDSIGNAL("heal", PropertyInfo(Variant::INT, "delta"), PropertyInfo(Variant::INT, "remaining")); + GDSIGNAL("health_changed", PropertyInfo(Variant::INT, "delta"), PropertyInfo(Variant::INT, "remaining")); + GDSIGNAL("death", PropertyInfo(Variant::INT, "delta")); } void Health::_enter_tree() {