diff --git a/src/player.cpp b/src/player.cpp index 88af953..c2e027b 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -19,6 +19,7 @@ void Player::_bind_methods() { #endif GDFUNCTION_ARGS(on_horizontal, "event", "value"); GDFUNCTION_ARGS(on_vertical, "event", "value"); + GDFUNCTION(get_is_moving); } void Player::_enter_tree() { @@ -31,7 +32,7 @@ void Player::_enter_tree() { void Player::_ready() { this->customization_init(); GDGAMEONLY(); - this->flat_view_init(); + this->flat_view_update(); this->input->listen_to(PlayerInput::Listener("move_left", "move_right", this, "on_horizontal")); this->input->listen_to(PlayerInput::Listener("move_forward", "move_back", this, "on_vertical")); } @@ -54,18 +55,19 @@ void Player::_physics_process(double deltaTime) { this->move_and_slide(); } +void Player::damage(Node *origin, int amount) { +} + void Player::set_customization_active(Node3D *node, bool active) { node->set_visible(active); node->set_process(active); } void Player::on_horizontal(Ref event, float value) { - UtilityFunctions::print("horizontal ", value); this->moveInput.x = value; } void Player::on_vertical(Ref event, float value) { - UtilityFunctions::print("vertical ", value); this->moveInput.y = value; } @@ -138,7 +140,7 @@ void Player::rotate_to_movement() { this->set_global_transform(trans); } -void Player::flat_view_init() { +void Player::flat_view_update() { Basis basis = this->get_viewport()->get_camera_3d()->get_global_transform().get_basis(); Vector3 right = basis.get_column(0); right = Vector3{-right.x, 0, -right.z}.normalized(); @@ -190,4 +192,8 @@ void Player::customization_init() { UtilityFunctions::print("removing ", key); } } + +bool Player::get_is_moving() const { + return this->is_on_floor() && !this->moveInput.is_zero_approx(); +} } // namespace godot diff --git a/src/player.hpp b/src/player.hpp index 88cca63..5f81adf 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -2,15 +2,17 @@ #define PLAYER_HPP #include +#include "constants.hpp" #include "godot_cpp/classes/animation_tree.hpp" #include "godot_cpp/classes/character_body3d.hpp" #include "godot_cpp/classes/input_event.hpp" #include "godot_cpp/classes/skeleton3d.hpp" +#include "hitable_interface.hpp" #include "player_input.hpp" #include namespace godot { -class Player : public CharacterBody3D { +class Player : public CharacterBody3D, public HitableInterface { GDCLASS(Player, CharacterBody3D) static void _bind_methods(); // the current customization state of a body part/attachment @@ -29,9 +31,9 @@ protected: // the skeleton of the customizable character model Skeleton3D *customizationParent{nullptr}; PlayerInput *input{nullptr}; - Basis flatViewBasis{}; + Basis flatViewBasis{identity::Basis}; - float walkSpeed{4.f}; + static float constexpr walkSpeed{4.f}; Vector2 moveInput{0.f, 0.f}; @@ -41,6 +43,8 @@ public: virtual void _process(double deltaTime) override; virtual void _physics_process(double deltaTime) override; + virtual void damage(Node *origin, int amount) override; + static void set_customization_active(Node3D *node, bool active); void on_horizontal(Ref event, float value); @@ -61,8 +65,9 @@ public: private: void rotate_to_movement(); - void flat_view_init(); + void flat_view_update(); void customization_init(); + bool get_is_moving() const; }; } // namespace godot