58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#include "enemy_rifleman.h"
|
|
#include "core/os/memory.h"
|
|
#include "scene/animation/animation_player.h"
|
|
#include "wave_survival/npc_unit.h"
|
|
#include "wave_survival/player_detector.h"
|
|
#include "wave_survival/state_machine.h"
|
|
|
|
void EnemyRifleman::_bind_methods() {
|
|
}
|
|
|
|
void EnemyRifleman::ready() {
|
|
get_fsm()->add_state(memnew(RiflemanPatrolState));
|
|
get_fsm()->add_state(memnew(RiflemanChaseState));
|
|
get_fsm()->add_state(memnew(RiflemanFireState));
|
|
}
|
|
|
|
void EnemyRifleman::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
default:
|
|
return;
|
|
case NOTIFICATION_READY:
|
|
ready();
|
|
return;
|
|
}
|
|
}
|
|
|
|
EnemyRifleman *RiflemanState::get_target() const {
|
|
return cast_to<EnemyRifleman>(get_body());
|
|
}
|
|
|
|
String RiflemanPatrolState::get_next_state() const {
|
|
if (get_body()->get_unit()->is_aware_of_player()) {
|
|
return RiflemanChaseState::get_class_static();
|
|
}
|
|
return get_class();
|
|
}
|
|
|
|
String RiflemanChaseState::get_next_state() const {
|
|
if (get_body()->get_detector()->line_of_sight_exists()) {
|
|
return RiflemanFireState::get_class_static();
|
|
}
|
|
return get_class();
|
|
}
|
|
|
|
void RiflemanFireState::enter_state() {
|
|
get_anim()->play("fire");
|
|
get_target()->set_movement_direction(Vector2());
|
|
}
|
|
|
|
String RiflemanFireState::get_next_state() const {
|
|
if (get_anim()->get_current_animation().is_empty()) {
|
|
return RiflemanFireState::get_class_static();
|
|
}
|
|
return get_class();
|
|
}
|