diff --git a/client/entities/characters/player.gd b/client/entities/characters/player.gd index 38ae7d07f75f3caf0f0867e9eb84cb415cf016bb..c19b556830ce7c87d301bad111cad9523bb74a55 100644 --- a/client/entities/characters/player.gd +++ b/client/entities/characters/player.gd @@ -5,13 +5,15 @@ puppet func getRemoteMovement(position:Vector3): self.set_translation(position) # Feedback when hurt -puppet func hurt(damages:int): - print("You suffered a hit and lost " + str(damages) + " HPs !") +puppet func hurt(hpNow:int): + print("You suffered a hit and are now at " + String(hpNow) + " !") # Feedback when killed puppet func die(killerId:int): print(str(killerId) + " killed " + self.name) # Hide the killed player (NB: the client is only about inputs and display) - self.set_visible(false) + #self.set_visible(false) + + \ No newline at end of file diff --git a/client/levels/test/game.gd b/client/levels/test/game.gd index ca1826038946735208d02c41bff95cd1d85635ba..08680e37e70bd30e3b2c5bfc31a7243f63cb1e6a 100644 --- a/client/levels/test/game.gd +++ b/client/levels/test/game.gd @@ -44,3 +44,8 @@ func getPlayerInput(): # Sent without safety resend rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpInput, jumpId, sprintInput, attackStateInput) + +puppet func backToLobby(): + #get_node("/root/lobby").show() + get_tree().quit() + queue_free() diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index af0a0e044799df94c7088e4c12973b7d352b8063..6454431bec4a9eab7b62a83c02df72fe9b587490 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -7,6 +7,9 @@ const MAX_CLIENTS = 2 var players = {} +const ENVIRONMENT_LAYER = 0 +const PLAYER_LAYER = 1 + func _ready(): # When a client connects to the server get_tree().connect("network_peer_connected", self, "_playerConnected") diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index c6eb89abfa2203731f884cf8e5793a2d3fae6682..a87dfd2b9beb688870c25bad4bf85c99f70af168 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -36,7 +36,7 @@ const FLOOR_NORMAL:Vector3 = Vector3(0,1,0) ######### ATTACKS VARS ######## -var isAlive:bool = true +onready var lastStrikerId:int = ownId; var isAttacking:bool = false onready var attackTimer:Tween = $attackTween @@ -59,17 +59,14 @@ var secondaryAttackDist:float = 1.2 var secondaryAttackDuration:float = 0.2 # Health points related values -var hpMax:int = 60 -var hpNow:int = hpMax - +var hp:int = 0 ######## FUNCTIONS ######## # called by the engine func _physics_process(delta): - if isAlive: - processMovement(delta) - broadcastMovement() + processMovement(delta) + broadcastMovement() # Called from the game script to update the vars @@ -102,10 +99,13 @@ func processMovement(delta): elif motion < 0: set_rotation_degrees(Vector3(0, 180, 0)) - # Reset permitted jump if on floor and decrease max number of jumps if falling if self.is_on_floor(): + # Reset the number of jumps left currentJump = 0 + # Reset the last striker + lastStrikerId = ownId elif currentJump == 0 && !isJumping: + # Initial jump prevented currentJump = 1 # Jump attempts computation @@ -195,22 +195,14 @@ func secondaryAttack(): # Called when detected by an attack's hitbox -func hurt(damages:int, killerId:int): - hpNow -= damages - - # Player still alive - if hpNow>0: - rpc_id(ownId, "hurt", damages) - - # Player killed - else: - rpc("die", killerId) - - # Bool checked in the physics processing - isAlive = false - - # Make the player traversable - collisionShape.set_disabled(true) +func hurt(damages:int, sourceId:int): + hp += damages + lastStrikerId = sourceId + rpc_unreliable_id(ownId, "hurt", hp) + +func die(): + rpc("die", lastStrikerId) + self.queue_free() ######## SIGNALS ######## diff --git a/server/levels/test/game.gd b/server/levels/test/game.gd index fef26315c0d5a9735640147d204db7b116f8f2f5..86489f1ce45bb299a628551eb2bd362675d6e1f0 100644 --- a/server/levels/test/game.gd +++ b/server/levels/test/game.gd @@ -1,13 +1,18 @@ extends Node -master func sendPlayerInputs(movementInput, jumpInput, jumpId, sprintInput, attackStateInput): +master func sendPlayerInputs(movementInput:int, jumpInput:bool, jumpId:int, sprintInput:bool, attackStateInput:int): # Get the input from a client and send it to the matching remote player - var senderId = get_tree().get_rpc_sender_id() - gamestate.get_node("/root/game/"+str(senderId)).getPlayerInputs(movementInput, jumpInput, jumpId, sprintInput, attackStateInput) + var senderId:int = get_tree().get_rpc_sender_id() + if gamestate.players.has(senderId): + gamestate.get_node("/root/game/"+str(senderId)).getPlayerInputs(movementInput, jumpInput, jumpId, sprintInput, attackStateInput) -# When the player enter the area under the map -func _on_killingFallArea_body_entered(body): - # Instant-kill with the server as killer - body.hurt(body.hpMax, 0) +# When the player exits the game area +func _on_killingFallArea_body_exited(body:PhysicsBody): + # Instant-kill if the body is a living player + if body.get_collision_layer_bit(gamestate.PLAYER_LAYER): + gamestate.players.erase(body.ownId) + rpc_id(body.ownId, "backToLobby") + #gamestate.disconnect_network_peer(body.ownId) + body.die() diff --git a/server/levels/test/game.tscn b/server/levels/test/game.tscn index 097b1edfe1299a95be82bb81b1fe5c2797eec3da..0e4f9308d78685900291e615b8732176abe9f014 100644 --- a/server/levels/test/game.tscn +++ b/server/levels/test/game.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://levels/test/bloc/bloc.tscn" type="PackedScene" id=2] [sub_resource type="BoxShape" id=1] -extents = Vector3( 175.136, 7.53585, 1 ) +extents = Vector3( 175.136, 87.8901, 1 ) [node name="game" type="Spatial"] script = ExtResource( 1 ) @@ -22,6 +22,7 @@ transform = Transform( 10, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ) transform = Transform( 5, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.15191, 0 ) [node name="spawnCollection" type="Spatial" parent="."] +transform = Transform( 0.996196, -0.0845788, 0.0209877, 0.084609, 0.996414, -0.000553806, -0.0208656, 0.00232744, 0.99978, 0, 0, 0 ) [node name="spawn1" type="Position3D" parent="spawnCollection"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 6, 0 ) @@ -35,6 +36,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 6, 0 ) [node name="killingFallArea" type="Area" parent="."] [node name="CollisionShape" type="CollisionShape" parent="killingFallArea"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -38.2712, 0 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.208731, 0 ) shape = SubResource( 1 ) -[connection signal="body_entered" from="killingFallArea" to="." method="_on_killingFallArea_body_entered"] +[connection signal="body_exited" from="killingFallArea" to="." method="_on_killingFallArea_body_exited"]