chore: WIP rifleman implementation
This commit is contained in:
parent
5f3e21f254
commit
7810bc415b
2 changed files with 69 additions and 9 deletions
|
|
@ -1,12 +1,26 @@
|
|||
#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() {
|
||||
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) {
|
||||
|
|
@ -17,10 +31,46 @@ void EnemyRifleman::_notification(int what) {
|
|||
default:
|
||||
return;
|
||||
case NOTIFICATION_ENTER_TREE:
|
||||
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;
|
||||
}
|
||||
|
||||
void RiflemanState::set_target(Node *node) {
|
||||
this->target = cast_to<EnemyRifleman>(node);
|
||||
}
|
||||
|
||||
EnemyRifleman *RiflemanState::get_target() const {
|
||||
return this->target;
|
||||
}
|
||||
|
||||
NpcUnit *RiflemanState::get_unit() const {
|
||||
return this->target->get_unit();
|
||||
}
|
||||
|
||||
NavigationAgent3D *RiflemanState::get_nav() const {
|
||||
return this->target->get_nav();
|
||||
}
|
||||
|
||||
AnimationPlayer *RiflemanState::get_anim() const {
|
||||
return this->target->get_anim();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue