-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcharacter_controller.cpp
61 lines (53 loc) · 2.17 KB
/
character_controller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/node2d.hpp>
#include <godot_cpp/variant/variant.hpp>
#include "core/assert.hpp"
#include "core/constants.hpp"
#include "entity/controller/character_controller.hpp"
#include "singletons/console.hpp"
#include "util/bind.hpp"
#include "util/engine.hpp"
#include "util/input.hpp"
#include "util/io.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::process_action_input(godot::Input* const input, double delta_time)
{
error_msg("process_action_input() not implemented in derived class");
}
void CharacterController::process_movement_input(godot::Input* const input, double delta_time)
{
error_msg("process_movement_input() not implemented in derived class");
}
void CharacterController::process_rotation_input(godot::Input* const input, double delta_time)
{
error_msg("process_rotation_input() not implemented in derived class");
}
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>();
}
}