61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#include "enemy_rifleman.h"
|
|
#include "core/os/memory.h"
|
|
#include "scene/animation/animation_player.h"
|
|
#include "wave_survival/macros.h"
|
|
#include "wave_survival/state_machine.h"
|
|
|
|
void EnemyRifleman::_bind_methods() {
|
|
BIND_PROPERTY(Variant::FLOAT, chase_speed);
|
|
}
|
|
|
|
void EnemyRifleman::on_child_entered(Node *node) {
|
|
if (StateMachine * fsm{ cast_to<StateMachine>(node) }) {
|
|
this->fsm = fsm;
|
|
}
|
|
if (node->has_node(NodePath("AnimationPlayer"))) {
|
|
this->anim = cast_to<AnimationPlayer>(node->get_node(NodePath("AnimationPlayer")));
|
|
}
|
|
}
|
|
|
|
void EnemyRifleman::ready() {
|
|
this->fsm->add_state(memnew(RiflemanPatrolState));
|
|
this->fsm->add_state(memnew(RiflemanSeekState));
|
|
this->fsm->add_state(memnew(RiflemanFireState));
|
|
}
|
|
|
|
void EnemyRifleman::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_ENTER_TREE:
|
|
if (!is_ready()) {
|
|
connect("child_entered", callable_mp(this, &self_type::on_child_entered));
|
|
}
|
|
return;
|
|
case NOTIFICATION_READY:
|
|
ready();
|
|
return;
|
|
}
|
|
}
|
|
|
|
void EnemyRifleman::set_chase_speed(float speed) {
|
|
this->chase_speed = speed;
|
|
}
|
|
|
|
float EnemyRifleman::get_chase_speed() const {
|
|
return this->chase_speed;
|
|
}
|
|
|
|
AnimationPlayer *EnemyRifleman::get_anim() const {
|
|
return this->anim;
|
|
}
|
|
|
|
EnemyRifleman *RiflemanState::get_target() const {
|
|
return cast_to<EnemyRifleman>(get_body());
|
|
}
|
|
|
|
void RiflemanPatrolState::enter_state() {
|
|
}
|