-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
300 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "nodes/character/character_controller.hpp" | ||
|
||
#include "util/bind.hpp" | ||
#include "util/constants.hpp" | ||
#include "util/engine.hpp" | ||
#include "util/input.hpp" | ||
#include "util/io.hpp" | ||
|
||
#include <godot_cpp/classes/input.hpp> | ||
#include <godot_cpp/classes/node2d.hpp> | ||
#include <godot_cpp/variant/variant.hpp> | ||
|
||
namespace rl | ||
{ | ||
void CharacterController::_process(double delta_time) | ||
{ | ||
if (engine::editor_active()) | ||
return; | ||
|
||
godot::Input* input_handler{ input::get() }; | ||
if (input_handler != nullptr) | ||
{ | ||
this->process_movement_input(input_handler, delta_time); | ||
this->process_rotation_input(input_handler, delta_time); | ||
this->process_action_input(input_handler, delta_time); | ||
|
||
m_elapsed_time += delta_time; | ||
if (m_elapsed_time > 1.0) | ||
{ | ||
m_elapsed_time = 0.0; | ||
this->emit_signal(event::position_changed, this->get_parent(), | ||
this->get_global_position()); | ||
} | ||
} | ||
} | ||
|
||
void CharacterController::_bind_methods() | ||
{ | ||
signal_binding<CharacterController, event::character_move>::add<godot::Vector2, double>(); | ||
signal_binding<CharacterController, event::character_rotate>::add<double, double>(); | ||
signal_binding<CharacterController, event::character_shoot>::add<godot::Object*>(); | ||
signal_binding<CharacterController, event::position_changed>::add<godot::Object*, | ||
godot::Vector2>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include <godot_cpp/classes/input.hpp> | ||
#include <godot_cpp/classes/node2d.hpp> | ||
|
||
namespace rl | ||
{ | ||
class CharacterController : public godot::Node2D | ||
{ | ||
GDCLASS(CharacterController, godot::Node2D); | ||
|
||
public: | ||
CharacterController() = default; | ||
virtual ~CharacterController() = default; | ||
|
||
void _process(double delta_time) override; | ||
|
||
virtual void process_action_input(godot::Input* const input, double delta_time) | ||
{ | ||
} | ||
|
||
virtual void process_movement_input(godot::Input* const input, double delta_time) | ||
{ | ||
} | ||
|
||
virtual void process_rotation_input(godot::Input* const input, double delta_time) | ||
{ | ||
} | ||
|
||
protected: | ||
enum class InputMode | ||
{ | ||
MouseAndKeyboard, | ||
Controller | ||
}; | ||
|
||
InputMode get_input_mode(godot::Input* const input); | ||
|
||
static void _bind_methods(); | ||
|
||
// template <class T, class B> | ||
// static void register_virtuals() | ||
//{ | ||
// godot::Node2D::register_virtuals<T, B>(); | ||
// if constexpr ( | ||
// !std::is_same_v<decltype(&B::process_action_input), | ||
// decltype(&T::process_action_input)>) | ||
// { | ||
// BIND_VIRTUAL_METHOD(T, process_action_input); | ||
// } | ||
// if constexpr (!std::is_same_v<decltype(&B::process_movement_input), | ||
// decltype(&T::process_movement_input)>) | ||
// { | ||
// BIND_VIRTUAL_METHOD(T, process_movement_input); | ||
// } | ||
// if constexpr (!std::is_same_v<decltype(&B::process_rotation_input), | ||
// decltype(&T::process_rotation_input)>) | ||
// { | ||
// BIND_VIRTUAL_METHOD(T, process_rotation_input); | ||
// } | ||
// } | ||
|
||
protected: | ||
// the active input mode for character controls | ||
InputMode m_input_mode{ InputMode::MouseAndKeyboard }; | ||
// target rotation | ||
double m_rotation_angle{ 0.0 }; | ||
// elapsed runtime (seconds) | ||
double m_elapsed_time{ 0.0 }; | ||
}; | ||
} |
Oops, something went wrong.