56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#include "enemy_wretched.h"
|
|
#include "scene/animation/animation_player.h"
|
|
#include "wave_survival/npc_unit.h"
|
|
#include "wave_survival/player_body.h"
|
|
#include "wave_survival/state_machine.h"
|
|
|
|
void EnemyWretched::_bind_methods() {}
|
|
|
|
void EnemyWretched::ready() {
|
|
get_fsm()->add_state(memnew(WretchedPatrolState));
|
|
get_fsm()->add_state(memnew(WretchedChaseState));
|
|
get_fsm()->add_state(memnew(WretchedAttackState));
|
|
}
|
|
|
|
void EnemyWretched::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_READY:
|
|
ready();
|
|
return;
|
|
}
|
|
}
|
|
|
|
EnemyWretched *WretchedState::get_target() const {
|
|
return cast_to<EnemyWretched>(get_body());
|
|
}
|
|
|
|
String WretchedPatrolState::get_next_state() const {
|
|
if (get_body()->get_unit()->is_aware_of_player()) {
|
|
return WretchedChaseState::get_class_static();
|
|
}
|
|
return get_class();
|
|
}
|
|
|
|
String WretchedChaseState::get_next_state() const {
|
|
if (get_body()->get_global_position().distance_to(PlayerBody::get_singleton()->get_global_position()) < 2.f) {
|
|
return WretchedAttackState::get_class_static();
|
|
}
|
|
return get_class();
|
|
}
|
|
|
|
void WretchedAttackState::enter_state() {
|
|
get_anim()->play("attack");
|
|
get_target()->set_movement_direction(Vector2());
|
|
}
|
|
|
|
String WretchedAttackState::get_next_state() const {
|
|
if (get_anim()->get_current_animation().is_empty()) {
|
|
return WretchedChaseState::get_class_static();
|
|
}
|
|
return get_class();
|
|
}
|