From 5b4ef6c022d130648970aacc954b4030f6ad0ec9 Mon Sep 17 00:00:00 2001 From: Canopteks <thomas.duhamel@protonmail.com> Date: Tue, 11 Feb 2020 16:13:05 +0100 Subject: [PATCH] cleaning up for the incoming merge with master --- client/scenes/entities/bloc/bloc.tscn | 9 +---- client/scenes/entities/player/player.gd | 5 +-- client/scenes/entities/player/player.tscn | 9 +---- client/scenes/levels/lobby/lobby.gd | 1 - client/scenes/levels/testnetwork/Node.gd | 40 --------------------- client/scenes/levels/testnetwork/Node.tscn | 6 ---- cmi2/Client/project.godot | 24 ------------- cmi2/Server/project.godot | 24 ------------- server/scenes/autoloads/gamestate.gd | 2 +- server/scenes/entities/player/player.gd | 41 ++++++++-------------- 10 files changed, 21 insertions(+), 140 deletions(-) delete mode 100644 client/scenes/levels/testnetwork/Node.gd delete mode 100644 client/scenes/levels/testnetwork/Node.tscn delete mode 100644 cmi2/Client/project.godot delete mode 100644 cmi2/Server/project.godot diff --git a/client/scenes/entities/bloc/bloc.tscn b/client/scenes/entities/bloc/bloc.tscn index 6d021e8..8d6ebc3 100644 --- a/client/scenes/entities/bloc/bloc.tscn +++ b/client/scenes/entities/bloc/bloc.tscn @@ -1,17 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [sub_resource type="CubeMesh" id=1] -[sub_resource type="BoxShape" id=2] - [node name="Bloc" type="Spatial"] [node name="MeshInstance" type="MeshInstance" parent="."] transform = Transform( 0.5, 0, 0, 0, 0.3, 0, 0, 0, 1, 0, 0, 0 ) mesh = SubResource( 1 ) material/0 = null - -[node name="StaticBody" type="StaticBody" parent="MeshInstance"] - -[node name="CollisionShape" type="CollisionShape" parent="MeshInstance/StaticBody"] -shape = SubResource( 2 ) diff --git a/client/scenes/entities/player/player.gd b/client/scenes/entities/player/player.gd index 7916621..b1de2aa 100644 --- a/client/scenes/entities/player/player.gd +++ b/client/scenes/entities/player/player.gd @@ -1,4 +1,5 @@ extends KinematicBody -remote func getRemoteMovement(position): - self.move_and_slide(position, Vector3(0,1,0), 0.05, 4) \ No newline at end of file +# Update the player's position based on the position computed by the remote scene on the server +puppet func getRemoteMovement(position): + self.set_translation(position) \ No newline at end of file diff --git a/client/scenes/entities/player/player.tscn b/client/scenes/entities/player/player.tscn index d768d61..3cfc970 100644 --- a/client/scenes/entities/player/player.tscn +++ b/client/scenes/entities/player/player.tscn @@ -1,17 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://scenes/entities/player/player.gd" type="Script" id=1] -[sub_resource type="BoxShape" id=1] -extents = Vector3( 0.175, 0.275, 0.7 ) - [node name="Player" type="KinematicBody"] script = ExtResource( 1 ) -[node name="Body_CollisionShape" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0.65, 0 ) -shape = SubResource( 1 ) - [node name="Model" type="Spatial" parent="."] [node name="CSGBox" type="CSGBox" parent="Model"] diff --git a/client/scenes/levels/lobby/lobby.gd b/client/scenes/levels/lobby/lobby.gd index 41dbeca..0603a64 100644 --- a/client/scenes/levels/lobby/lobby.gd +++ b/client/scenes/levels/lobby/lobby.gd @@ -29,7 +29,6 @@ func _on_joinButton_pressed(): #func _player_connected(): # print("You successfuly joined the server with the id " + str(gamestate.get_network_unique_id())) # -# #func _connection_failed(): # print("Connection failure") # diff --git a/client/scenes/levels/testnetwork/Node.gd b/client/scenes/levels/testnetwork/Node.gd deleted file mode 100644 index a936c80..0000000 --- a/client/scenes/levels/testnetwork/Node.gd +++ /dev/null @@ -1,40 +0,0 @@ -#client - -extends Node - -var peer = NetworkedMultiplayerENet.new() -export var is_server = false - -func _ready(): - peer.create_client("91.121.81.74",10001) - get_tree().set_network_peer(peer) - - get_tree().connect("connected_to_server", self, "_connected_ok") #connexion effectuée - get_tree().connect("connection_failed", self, "_connected_failed") #connextion error - get_tree().connect("server_disconnected", self, "_server_disconnected") #déconnexion - - - - - -remote func get_message(mess): - if mess == "quit": - print("Received order to quit") - get_tree().set_network_peer(null) - get_tree().quit() - else: - print(mess) - -#Quand connexion effectuée -func _connected_ok(): - print("Connection to server successful") - set_network_master(get_tree().get_network_unique_id()) - rpc("get_message","Hello there") - rpc("get_message","quit") - -#Quand connection error -func _connected_failed(): - print("Failed to connect to server") - - - diff --git a/client/scenes/levels/testnetwork/Node.tscn b/client/scenes/levels/testnetwork/Node.tscn deleted file mode 100644 index d8855e2..0000000 --- a/client/scenes/levels/testnetwork/Node.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://scenes/levels/testnetwork/Node.gd" type="Script" id=1] - -[node name="Node" type="Node"] -script = ExtResource( 1 ) diff --git a/cmi2/Client/project.godot b/cmi2/Client/project.godot deleted file mode 100644 index d403908..0000000 --- a/cmi2/Client/project.godot +++ /dev/null @@ -1,24 +0,0 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - -config_version=4 - -_global_script_classes=[ ] -_global_script_class_icons={ - -} - -[application] - -config/name="Client" -run/main_scene="res://Scenes/Level.tscn" -config/icon="res://img/icon.png" - -[rendering] - -environment/default_environment="res://default_env.tres" diff --git a/cmi2/Server/project.godot b/cmi2/Server/project.godot deleted file mode 100644 index ccfeb91..0000000 --- a/cmi2/Server/project.godot +++ /dev/null @@ -1,24 +0,0 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - -config_version=4 - -_global_script_classes=[ ] -_global_script_class_icons={ - -} - -[application] - -config/name="Server" -run/main_scene="res://Scenes/Server.tscn" -config/icon="res://img/icon.png" - -[rendering] - -environment/default_environment="res://default_env.tres" diff --git a/server/scenes/autoloads/gamestate.gd b/server/scenes/autoloads/gamestate.gd index 6f1606f..d355e54 100644 --- a/server/scenes/autoloads/gamestate.gd +++ b/server/scenes/autoloads/gamestate.gd @@ -3,7 +3,7 @@ extends Node const GAMEPATH = "/root/game/" const PORT = 10001 -const MAX_CLIENTS = 2 +const MAX_CLIENTS = 1 var players = {} diff --git a/server/scenes/entities/player/player.gd b/server/scenes/entities/player/player.gd index e8ed31c..3e334ba 100644 --- a/server/scenes/entities/player/player.gd +++ b/server/scenes/entities/player/player.gd @@ -21,22 +21,19 @@ const GRAVITY:float = -28.0 # Velocity updated continuously by move_and_slide var vel:Vector3 = Vector3() -var motion:Vector3 = Vector3() + +const FLOOR_NORMAL:Vector3 = Vector3(0,1,0) + +var motion:float = 0 # called by the engine func _physics_process(delta): processMovement(delta) - # TODO: Reactivate if we don't use it from processMovement - #broadcastMovement(delta) + broadcastMovement(delta) # Called from the game script to update the vars func getPlayerInputs(movementInput, sprintInput, jumpInput): - motion = Vector3() - - motion.x = movementInput - motion.y= 0 - motion.z = 0 - + motion = movementInput isSprinting = sprintInput isJumping = jumpInput @@ -49,7 +46,8 @@ func processMovement(delta): vel.y += delta * GRAVITY # Speed of the player - var target = motion + var target = Vector3(motion, 0, 0) + if isSprinting: target *= MAX_SPRINT_SPEED else: @@ -57,10 +55,8 @@ func processMovement(delta): # Acceleration of the player if he is moving horizontally var accel - var hvel:Vector3 = vel - hvel.y = 0 - hvel.z = 0 - if motion.dot(hvel)>0: + var hvel:Vector3 = Vector3(vel.x,0,0) + if target.dot(hvel)>0: if isSprinting: accel = SPRINT_ACCEL else: @@ -68,19 +64,12 @@ func processMovement(delta): else: accel = DEACCEL - # Interpolating speed and acceleration through time - hvel = hvel.linear_interpolate(target, accel * delta) - - # Final velocity - vel.x = hvel.x - - # Send the velocity before its alteration by move_and_slide. - # (The alteration will be sent after modification by the inputs of the last iteration.) - # It is not filthy. - broadcastMovement(delta) + # Interpolating speed and acceleration through time and getting it + vel.x = hvel.linear_interpolate(target, accel * delta).x # Update the velocity after the collisions (physical engine ftw) - vel = self.move_and_slide(vel, Vector3(0,1,0), 0.05, 4) + vel = self.move_and_slide(vel, FLOOR_NORMAL) func broadcastMovement(delta): - rpc("getRemoteMovement", vel) \ No newline at end of file + # Send the position of the player + rpc("getRemoteMovement", self.get_translation()) \ No newline at end of file -- GitLab