feat: created tunnels gamemode and player objects
This commit is contained in:
parent
beb1fe05f2
commit
168cba5d03
9 changed files with 181 additions and 7 deletions
|
|
@ -3,6 +3,14 @@
|
|||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
#include "utils/game_root.hpp"
|
||||
#include "utils/game_mode.hpp"
|
||||
#include "utils/game_state.hpp"
|
||||
#include "utils/level.hpp"
|
||||
#include "utils/spawn_point.hpp"
|
||||
#include "utils/player_input.hpp"
|
||||
#include "tunnels_game_mode.hpp"
|
||||
#include "tunnels_player.hpp"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
|
|
@ -11,14 +19,17 @@ void initialize_gdextension_types(ModuleInitializationLevel p_level)
|
|||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
ClassDB::register_class<GameRoot>();
|
||||
ClassDB::register_class<GameRoot3D>();
|
||||
ClassDB::register_class<SpawnPoint3D>();
|
||||
ClassDB::register_class<PlayerInput>();
|
||||
ClassDB::register_class<GameMode>();
|
||||
ClassDB::register_class<GameState>();
|
||||
ClassDB::register_class<Level3D>();
|
||||
ClassDB::register_class<TunnelsGameMode>();
|
||||
ClassDB::register_class<TunnelsPlayer>();
|
||||
}
|
||||
|
||||
//void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
|
||||
// if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
// Initialization
|
||||
|
|
@ -26,7 +37,6 @@ extern "C"
|
|||
{
|
||||
GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
|
||||
init_obj.register_initializer(initialize_gdextension_types);
|
||||
// init_obj.register_terminator(uninitialize_gdextension_types);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||
|
||||
return init_obj.init();
|
||||
|
|
|
|||
6
src/tunnels_game_mode.cpp
Normal file
6
src/tunnels_game_mode.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "tunnels_game_mode.hpp"
|
||||
|
||||
namespace godot {
|
||||
void TunnelsGameMode::_bind_methods() {
|
||||
}
|
||||
}
|
||||
14
src/tunnels_game_mode.hpp
Normal file
14
src/tunnels_game_mode.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef TUNNELS_GAME_MODE_HPP
|
||||
#define TUNNELS_GAME_MODE_HPP
|
||||
|
||||
#include "utils/game_mode.hpp"
|
||||
|
||||
namespace godot {
|
||||
class TunnelsGameMode : public GameMode {
|
||||
GDCLASS(TunnelsGameMode, GameMode)
|
||||
static void _bind_methods();
|
||||
public:
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !TUNNELS_GAME_MODE_HPP
|
||||
47
src/tunnels_player.cpp
Normal file
47
src/tunnels_player.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include "tunnels_player.hpp"
|
||||
#include "utils/godot_macros.h"
|
||||
#include "utils/player_input.hpp"
|
||||
#include <godot_cpp/classes/input_event.hpp>
|
||||
#include <godot_cpp/classes/viewport.hpp>
|
||||
|
||||
namespace godot {
|
||||
float const TunnelsPlayer::MOVE_SPEED{0.f};
|
||||
|
||||
void TunnelsPlayer::_bind_methods() {
|
||||
#define CLASSNAME TunnelsPlayer
|
||||
GDFUNCTION_ARGS(horizontal_move_input, "event", "value");
|
||||
GDFUNCTION_ARGS(vertical_move_input, "event", "value");
|
||||
}
|
||||
|
||||
void TunnelsPlayer::_ready() { GDGAMEONLY();
|
||||
this->camera = this->get_viewport()->get_camera_3d();
|
||||
}
|
||||
|
||||
void TunnelsPlayer::_physics_process(double delta_time) { GDGAMEONLY();
|
||||
this->set_velocity(this->get_world_move_input());
|
||||
this->move_and_slide();
|
||||
}
|
||||
|
||||
void TunnelsPlayer::setup_player_input(PlayerInput *input) {
|
||||
input->listen_to(PlayerInput::Listener("move_right", "move_left", this, "horizontal_move_input"));
|
||||
input->listen_to(PlayerInput::Listener("move_forward", "move_backward", this, "vertical_move_input"));
|
||||
}
|
||||
|
||||
Node *TunnelsPlayer::to_node() {
|
||||
return Object::cast_to<Node>(this);
|
||||
}
|
||||
|
||||
void TunnelsPlayer::horizontal_move_input(Ref<InputEvent> event, float value) {
|
||||
this->move_input.x = value;
|
||||
}
|
||||
|
||||
void TunnelsPlayer::vertical_move_input(Ref<InputEvent> event, float value) {
|
||||
this->move_input.y = value;
|
||||
}
|
||||
|
||||
Vector3 TunnelsPlayer::get_world_move_input() const {
|
||||
Basis const camera_basis = camera->get_global_transform().get_basis();
|
||||
return this->move_input.x * camera_basis.get_column(0)
|
||||
+ this->move_input.y * camera_basis.get_column(2);
|
||||
}
|
||||
}
|
||||
35
src/tunnels_player.hpp
Normal file
35
src/tunnels_player.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef TUNNELS_PLAYER_HPP
|
||||
#define TUNNELS_PLAYER_HPP
|
||||
|
||||
#include "utils/player.hpp"
|
||||
#include "utils/player_input.hpp"
|
||||
#include <godot_cpp/classes/camera3d.hpp>
|
||||
#include <godot_cpp/classes/character_body3d.hpp>
|
||||
#include <godot_cpp/classes/input_event.hpp>
|
||||
|
||||
namespace godot {
|
||||
class TunnelsPlayer : public CharacterBody3D, public IPlayer {
|
||||
GDCLASS(TunnelsPlayer, CharacterBody3D);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual void _ready() override;
|
||||
virtual void _physics_process(double delta_time) override;
|
||||
|
||||
virtual void setup_player_input(PlayerInput *input) override;
|
||||
virtual Node *to_node() override;
|
||||
|
||||
void horizontal_move_input(Ref<InputEvent> event, float value);
|
||||
void vertical_move_input(Ref<InputEvent> event, float value);
|
||||
|
||||
Vector3 get_world_move_input() const;
|
||||
private:
|
||||
Vector2 move_input{0,0};
|
||||
|
||||
Camera3D *camera{nullptr};
|
||||
public:
|
||||
static float const MOVE_SPEED;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // !TUNNELS_PLAYER_HPP
|
||||
Loading…
Add table
Add a link
Reference in a new issue