153 lines
3.9 KiB
C++
153 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include "break_utopia/macros.h"
|
|
#include "player_body.h"
|
|
#include "scene/3d/mesh_instance_3d.h"
|
|
#include "scene/animation/animation_node_state_machine.h"
|
|
#include "scene/animation/animation_tree.h"
|
|
#include "scene/resources/material.h"
|
|
|
|
class PlayerState : public CharacterState {
|
|
GDCLASS(PlayerState, CharacterState);
|
|
static void _bind_methods();
|
|
void ready();
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
void apply_root_motion(double delta);
|
|
void turn_toward_input(float speed);
|
|
PlayerBody *get_body() const { return cast_to<PlayerBody>(get_parent()); }
|
|
void input_trigger_entry_actions(Ref<InputEvent> const &what);
|
|
|
|
private:
|
|
AnimationTree *anim{ nullptr };
|
|
Ref<AnimationNodeStateMachinePlayback> anim_fsm{};
|
|
|
|
protected:
|
|
GET_SET_FNS(AnimationTree *, anim);
|
|
GET_SET_FNS(Ref<AnimationNodeStateMachinePlayback>, anim_fsm);
|
|
};
|
|
|
|
class PlayerIdleState : public PlayerState {
|
|
GDCLASS(PlayerIdleState, PlayerState);
|
|
static void _bind_methods();
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
void state_entered() override;
|
|
void state_exited() override;
|
|
void unhandled_input(Ref<InputEvent> const &what) override;
|
|
};
|
|
|
|
class PlayerRunState : public PlayerState {
|
|
GDCLASS(PlayerRunState, PlayerState);
|
|
static void _bind_methods();
|
|
void process(double delta);
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
void unhandled_input(Ref<InputEvent> const &what) override;
|
|
void state_entered() override;
|
|
void state_exited() override;
|
|
|
|
private:
|
|
float rotation_speed{ 11.f };
|
|
|
|
public:
|
|
GET_SET_FNS(float, rotation_speed);
|
|
};
|
|
|
|
class PlayerFallState : public PlayerState {
|
|
GDCLASS(PlayerFallState, PlayerState);
|
|
static void _bind_methods();
|
|
void process_physics(double delta);
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
void state_entered() override;
|
|
void state_exited() override;
|
|
};
|
|
|
|
class PlayerBasicAttackState : public PlayerState {
|
|
GDCLASS(PlayerBasicAttackState, PlayerState);
|
|
static void _bind_methods();
|
|
void process(double delta);
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
void unhandled_input(Ref<InputEvent> const &what) override;
|
|
void state_entered() override;
|
|
void state_exited() override;
|
|
|
|
private:
|
|
String animation_name{ "swing_1" };
|
|
float trigger_slow_margin{ 0.1 };
|
|
float trigger_fast_margin{ 0.2 };
|
|
float input_slow_margin{ 0.3 };
|
|
NodePath next_fast{};
|
|
NodePath next_slow{};
|
|
NodePath next_special_fast{};
|
|
NodePath next_special_slow{};
|
|
MeshInstance3D *hammer_model{ nullptr };
|
|
Ref<StandardMaterial3D> hammer_attack_outline{};
|
|
double delta_since_start{ 0.0 };
|
|
float anim_length{};
|
|
enum NextAttack {
|
|
None,
|
|
AttackLightSlow = 1,
|
|
AttackLightFast = 2,
|
|
AttackSpecialSlow = 3,
|
|
AttackSpecialFast = 4,
|
|
};
|
|
NextAttack next_queued{ None };
|
|
bool animation_started{ false };
|
|
|
|
public:
|
|
GET_SET_FNS(String, animation_name);
|
|
GET_SET_FNS(NodePath, next_fast);
|
|
GET_SET_FNS(NodePath, next_slow);
|
|
GET_SET_FNS(NodePath, next_special_fast);
|
|
GET_SET_FNS(NodePath, next_special_slow);
|
|
GET_SET_FNS(float, trigger_slow_margin);
|
|
GET_SET_FNS(float, trigger_fast_margin);
|
|
GET_SET_FNS(float, input_slow_margin);
|
|
GET_SET_FNS(MeshInstance3D *, hammer_model);
|
|
GET_SET_FNS(Ref<StandardMaterial3D>, hammer_attack_outline);
|
|
};
|
|
|
|
class PlayerSpecialAttackState : public PlayerBasicAttackState {
|
|
GDCLASS(PlayerSpecialAttackState, PlayerBasicAttackState);
|
|
static void _bind_methods();
|
|
void fail_activation();
|
|
|
|
protected:
|
|
void state_entered() override;
|
|
void state_exited() override;
|
|
|
|
private:
|
|
double meter_cost{ .1 };
|
|
bool activated_succesful{ false };
|
|
|
|
public:
|
|
GET_SET_FNS(double, meter_cost);
|
|
};
|
|
|
|
class PlayerHurtState : public PlayerState {
|
|
GDCLASS(PlayerHurtState, PlayerState);
|
|
static void _bind_methods();
|
|
void process(double delta);
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
void state_entered() override;
|
|
void state_exited() override;
|
|
|
|
private:
|
|
String animation_name{ "hurt" };
|
|
double anim_length{ 0.0 };
|
|
double delta_since_start{ 0.0 };
|
|
bool animation_started{ false };
|
|
|
|
public:
|
|
GET_SET_FNS(String, animation_name);
|
|
};
|