feat: simplifying enemy state logic
This commit is contained in:
parent
603b3afcc2
commit
710e9c7bde
6 changed files with 148 additions and 154 deletions
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef ENEMY_WRETCHED_H
|
||||
#define ENEMY_WRETCHED_H
|
||||
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "wave_survival/enemy_body.h"
|
||||
#include "wave_survival/state.h"
|
||||
class PatrolPath;
|
||||
|
|
@ -11,56 +10,28 @@ class StateMachine;
|
|||
class EnemyWretched : public EnemyBody {
|
||||
GDCLASS(EnemyWretched, EnemyBody);
|
||||
static void _bind_methods();
|
||||
void on_child_entered(Node *node);
|
||||
void ready();
|
||||
|
||||
protected:
|
||||
void _notification(int what);
|
||||
|
||||
public:
|
||||
void set_chase_speed(float speed);
|
||||
float get_chase_speed() const;
|
||||
AnimationPlayer *get_anim() const;
|
||||
|
||||
private:
|
||||
float chase_speed{ 5.f };
|
||||
StateMachine *fsm{ nullptr };
|
||||
AnimationPlayer *anim{ nullptr };
|
||||
};
|
||||
|
||||
/* ============================== STATES ============================== */
|
||||
|
||||
class WretchedState : public State {
|
||||
class WretchedState : public EnemyState {
|
||||
GDCLASS(WretchedState, State);
|
||||
static void _bind_methods() {}
|
||||
|
||||
public:
|
||||
virtual void set_target(Node *node) override;
|
||||
EnemyWretched *get_target() const;
|
||||
NpcUnit *get_unit() const;
|
||||
NavigationAgent3D *get_nav() const;
|
||||
AnimationPlayer *get_anim() const;
|
||||
|
||||
private:
|
||||
EnemyWretched *target{ nullptr };
|
||||
};
|
||||
|
||||
class WretchedPatrolState : public WretchedState {
|
||||
GDCLASS(WretchedPatrolState, WretchedState);
|
||||
class WretchedPatrolState : public PatrolState {
|
||||
GDCLASS(WretchedPatrolState, PatrolState);
|
||||
static void _bind_methods() {}
|
||||
void set_patrol_target(Vector3 path_point);
|
||||
void on_velocity_calculated(Vector3 direction);
|
||||
|
||||
public:
|
||||
virtual void enter_state() override;
|
||||
virtual void process(double delta) override;
|
||||
virtual String get_next_state() const override;
|
||||
virtual void exit_state() override;
|
||||
|
||||
private:
|
||||
int path_point{ 0 };
|
||||
PatrolPath *path{ nullptr };
|
||||
Callable mp_on_velocity_calculated{ callable_mp(this, &self_type::on_velocity_calculated) };
|
||||
String get_next_state() const override;
|
||||
};
|
||||
|
||||
class WretchedChaseState : public WretchedState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue