Skip to content
Snippets Groups Projects
Commit 42da9a5d authored by Canopteks's avatar Canopteks
Browse files

commit of minimal version, dying is smooth and kick you out of the game

parent bc0550c8
Branches lifendeath
Tags
No related merge requests found
...@@ -5,13 +5,15 @@ puppet func getRemoteMovement(position:Vector3): ...@@ -5,13 +5,15 @@ puppet func getRemoteMovement(position:Vector3):
self.set_translation(position) self.set_translation(position)
# Feedback when hurt # Feedback when hurt
puppet func hurt(damages:int): puppet func hurt(hpNow:int):
print("You suffered a hit and lost " + str(damages) + " HPs !") print("You suffered a hit and are now at " + String(hpNow) + " !")
# Feedback when killed # Feedback when killed
puppet func die(killerId:int): puppet func die(killerId:int):
print(str(killerId) + " killed " + self.name) print(str(killerId) + " killed " + self.name)
# Hide the killed player (NB: the client is only about inputs and display) # 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
...@@ -44,3 +44,8 @@ func getPlayerInput(): ...@@ -44,3 +44,8 @@ func getPlayerInput():
# Sent without safety resend # Sent without safety resend
rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpInput, jumpId, sprintInput, attackStateInput) rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpInput, jumpId, sprintInput, attackStateInput)
puppet func backToLobby():
#get_node("/root/lobby").show()
get_tree().quit()
queue_free()
...@@ -7,6 +7,9 @@ const MAX_CLIENTS = 2 ...@@ -7,6 +7,9 @@ const MAX_CLIENTS = 2
var players = {} var players = {}
const ENVIRONMENT_LAYER = 0
const PLAYER_LAYER = 1
func _ready(): func _ready():
# When a client connects to the server # When a client connects to the server
get_tree().connect("network_peer_connected", self, "_playerConnected") get_tree().connect("network_peer_connected", self, "_playerConnected")
......
...@@ -36,7 +36,7 @@ const FLOOR_NORMAL:Vector3 = Vector3(0,1,0) ...@@ -36,7 +36,7 @@ const FLOOR_NORMAL:Vector3 = Vector3(0,1,0)
######### ATTACKS VARS ######## ######### ATTACKS VARS ########
var isAlive:bool = true onready var lastStrikerId:int = ownId;
var isAttacking:bool = false var isAttacking:bool = false
onready var attackTimer:Tween = $attackTween onready var attackTimer:Tween = $attackTween
...@@ -59,17 +59,14 @@ var secondaryAttackDist:float = 1.2 ...@@ -59,17 +59,14 @@ var secondaryAttackDist:float = 1.2
var secondaryAttackDuration:float = 0.2 var secondaryAttackDuration:float = 0.2
# Health points related values # Health points related values
var hpMax:int = 60 var hp:int = 0
var hpNow:int = hpMax
######## FUNCTIONS ######## ######## FUNCTIONS ########
# called by the engine # called by the engine
func _physics_process(delta): func _physics_process(delta):
if isAlive: processMovement(delta)
processMovement(delta) broadcastMovement()
broadcastMovement()
# Called from the game script to update the vars # Called from the game script to update the vars
...@@ -102,10 +99,13 @@ func processMovement(delta): ...@@ -102,10 +99,13 @@ func processMovement(delta):
elif motion < 0: elif motion < 0:
set_rotation_degrees(Vector3(0, 180, 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(): if self.is_on_floor():
# Reset the number of jumps left
currentJump = 0 currentJump = 0
# Reset the last striker
lastStrikerId = ownId
elif currentJump == 0 && !isJumping: elif currentJump == 0 && !isJumping:
# Initial jump prevented
currentJump = 1 currentJump = 1
# Jump attempts computation # Jump attempts computation
...@@ -195,22 +195,14 @@ func secondaryAttack(): ...@@ -195,22 +195,14 @@ func secondaryAttack():
# Called when detected by an attack's hitbox # Called when detected by an attack's hitbox
func hurt(damages:int, killerId:int): func hurt(damages:int, sourceId:int):
hpNow -= damages hp += damages
lastStrikerId = sourceId
# Player still alive rpc_unreliable_id(ownId, "hurt", hp)
if hpNow>0:
rpc_id(ownId, "hurt", damages) func die():
rpc("die", lastStrikerId)
# Player killed self.queue_free()
else:
rpc("die", killerId)
# Bool checked in the physics processing
isAlive = false
# Make the player traversable
collisionShape.set_disabled(true)
######## SIGNALS ######## ######## SIGNALS ########
......
extends Node 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 # Get the input from a client and send it to the matching remote player
var senderId = get_tree().get_rpc_sender_id() var senderId:int = get_tree().get_rpc_sender_id()
gamestate.get_node("/root/game/"+str(senderId)).getPlayerInputs(movementInput, jumpInput, jumpId, sprintInput, attackStateInput) 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 # When the player exits the game area
func _on_killingFallArea_body_entered(body): func _on_killingFallArea_body_exited(body:PhysicsBody):
# Instant-kill with the server as killer # Instant-kill if the body is a living player
body.hurt(body.hpMax, 0) 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()
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
[ext_resource path="res://levels/test/bloc/bloc.tscn" type="PackedScene" id=2] [ext_resource path="res://levels/test/bloc/bloc.tscn" type="PackedScene" id=2]
[sub_resource type="BoxShape" id=1] [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"] [node name="game" type="Spatial"]
script = ExtResource( 1 ) script = ExtResource( 1 )
...@@ -22,6 +22,7 @@ transform = Transform( 10, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 ) ...@@ -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 ) transform = Transform( 5, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.15191, 0 )
[node name="spawnCollection" type="Spatial" parent="."] [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"] [node name="spawn1" type="Position3D" parent="spawnCollection"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 6, 0 ) 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 ) ...@@ -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="killingFallArea" type="Area" parent="."]
[node name="CollisionShape" type="CollisionShape" parent="killingFallArea"] [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 ) 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"]
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment