break-utopia/modules/break_utopia/player_body.h

55 lines
1.5 KiB
C++

#pragma once
#include "core/input/input_event.h"
#include "scene/3d/physics/character_body_3d.h"
class PlayerBody : public CharacterBody3D {
GDCLASS(PlayerBody, CharacterBody3D);
static void _bind_methods();
void physics_process(double delta);
void on_child_entered(Node *node);
protected:
void _notification(int what);
void process_movement_input();
virtual void unhandled_input(Ref<InputEvent> const &what) override;
public:
static PlayerBody *get_singleton();
void deal_damage(double damage);
Vector3 get_transformed_movement_input() const;
private:
Vector2 movement_input{};
class CharacterState *default_state{ nullptr };
static PlayerBody *singleton;
};
class CharacterState : public Node {
GDCLASS(CharacterState, Node);
static void _bind_methods();
protected:
void _notification(int what);
void switch_state(NodePath path);
inline void switch_state(String name) { switch_state(NodePath("../" + name)); }
template <class TNewState>
void switch_state() { switch_state(TNewState::get_class_static()); }
void stack_state(NodePath name);
inline void stack_state(String name) { stack_state(NodePath("../" + name)); }
template <class TStackState>
inline void stack_state() { stack_state(TStackState::get_class_static()); }
virtual void state_entered();
virtual void state_exited();
public:
void set_state_active(bool active);
private:
bool active_state{ false };
public:
static String const sig_state_entered;
static String const sig_state_exited;
bool get_state_active() const { return this->active_state; }
};