feat: created tunnels gamemode and player objects
This commit is contained in:
		
							parent
							
								
									beb1fe05f2
								
							
						
					
					
						commit
						168cba5d03
					
				
							
								
								
									
										6
									
								
								godot/game_root.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								godot/game_root.tscn
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| [gd_scene load_steps=2 format=3 uid="uid://cmdfv4g8iqs2p"] | ||||
| 
 | ||||
| [ext_resource type="PackedScene" uid="uid://m36guasmi3c1" path="res://test_level.tscn" id="1_4g2mr"] | ||||
| 
 | ||||
| [node name="GameRoot" type="GameRoot3D"] | ||||
| first_boot_level = ExtResource("1_4g2mr") | ||||
							
								
								
									
										6
									
								
								godot/player.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								godot/player.tscn
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| [gd_scene format=3 uid="uid://cqkbxe758jr7p"] | ||||
| 
 | ||||
| [node name="TunnelsPlayer" type="TunnelsPlayer"] | ||||
| 
 | ||||
| [node name="Camera3D" type="Camera3D" parent="."] | ||||
| transform = Transform3D(1, 0, 0, 0, 0.971276, 0.237957, 0, -0.237957, 0.971276, 0, 1.20073, 1.85333) | ||||
|  | @ -11,5 +11,29 @@ config_version=5 | |||
| [application] | ||||
| 
 | ||||
| config/name="godot cpp template" | ||||
| run/main_scene="res://game_root.tscn" | ||||
| config/features=PackedStringArray("4.2", "Forward Plus") | ||||
| config/icon="res://icon.svg" | ||||
| 
 | ||||
| [input] | ||||
| 
 | ||||
| move_left={ | ||||
| "deadzone": 0.5, | ||||
| "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
| move_right={ | ||||
| "deadzone": 0.5, | ||||
| "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
| move_forward={ | ||||
| "deadzone": 0.5, | ||||
| "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
| move_backward={ | ||||
| "deadzone": 0.5, | ||||
| "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) | ||||
| ] | ||||
| } | ||||
|  |  | |||
							
								
								
									
										26
									
								
								godot/test_level.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								godot/test_level.tscn
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| [gd_scene load_steps=6 format=3 uid="uid://m36guasmi3c1"] | ||||
| 
 | ||||
| [ext_resource type="PackedScene" uid="uid://cqkbxe758jr7p" path="res://player.tscn" id="1_hv5rj"] | ||||
| 
 | ||||
| [sub_resource type="GameState" id="GameState_k4j3x"] | ||||
| 
 | ||||
| [sub_resource type="TunnelsGameMode" id="TunnelsGameMode_itn7y"] | ||||
| game_state = SubResource("GameState_k4j3x") | ||||
| player_scene = ExtResource("1_hv5rj") | ||||
| 
 | ||||
| [sub_resource type="BoxMesh" id="BoxMesh_5glbk"] | ||||
| size = Vector3(20, 0.25, 20) | ||||
| 
 | ||||
| [sub_resource type="BoxShape3D" id="BoxShape3D_kacqg"] | ||||
| size = Vector3(20, 0.25, 20) | ||||
| 
 | ||||
| [node name="Level3D" type="Level3D"] | ||||
| game_mode_prototype = SubResource("TunnelsGameMode_itn7y") | ||||
| 
 | ||||
| [node name="MeshInstance3D" type="MeshInstance3D" parent="."] | ||||
| mesh = SubResource("BoxMesh_5glbk") | ||||
| 
 | ||||
| [node name="StaticBody3D" type="StaticBody3D" parent="."] | ||||
| 
 | ||||
| [node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D"] | ||||
| shape = SubResource("BoxShape3D_kacqg") | ||||
|  | @ -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…
	
		Reference in a new issue
	
	 Sara
						Sara