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
No related merge requests found
......@@ -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
......@@ -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()
......@@ -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")
......
......@@ -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 ########
......
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()
......@@ -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"]
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