From 579146a2e5621b9230002774c7a789851b72abe6 Mon Sep 17 00:00:00 2001
From: Adonis Stavridis <adonis-ioannis.stavridis@etu.unistra.fr>
Date: Fri, 27 Mar 2020 17:38:06 +0100
Subject: [PATCH] #116 fix unresponsive jump

---
 client/levels/test/game.gd                  |  7 +------
 server/entities/characters/Class1/class1.gd |  2 +-
 server/entities/characters/player.gd        | 10 +++-------
 server/levels/test/game.gd                  |  5 ++---
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/client/levels/test/game.gd b/client/levels/test/game.gd
index 1bf1493..68e7f56 100644
--- a/client/levels/test/game.gd
+++ b/client/levels/test/game.gd
@@ -2,7 +2,6 @@ extends Node
 
 # Movements
 var movementInput:int = 0
-var jumpInput:bool = false      # Know if the player wants to jump
 var jumpId:int = 0              # Distinguish 2 different jumps
 var mouseX:int = 0							# Mouse X percentage
 var mouseY:int = 0							# Mouse Y percentage
@@ -31,10 +30,6 @@ func getPlayerInput():
 
 	if Input.is_action_just_pressed("movementJump"):
 		jumpId += 1
-	if Input.is_action_pressed("movementJump"):
-		jumpInput = true
-	else:
-		jumpInput = false
 
 	if Input.is_action_pressed("primaryAttack"):
 		attackStateInput = PUNCH
@@ -46,7 +41,7 @@ func getPlayerInput():
 		mouseY = int(mousePosition.y/vpSize.y * 100) - 50
 
 	# Sent without safety resend
-	rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpInput, jumpId,
+	rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpId,
 	attackStateInput, mouseX, mouseY)
 
 
diff --git a/server/entities/characters/Class1/class1.gd b/server/entities/characters/Class1/class1.gd
index 056b005..b0de48a 100644
--- a/server/entities/characters/Class1/class1.gd
+++ b/server/entities/characters/Class1/class1.gd
@@ -3,7 +3,7 @@ extends "res://entities/characters/player.gd"
 # Called when the node enters the scene tree for the first time.
 func _ready():
 	# Modification for this character
-	maxJump = 3
+	maxJump = 2
 
 
 # Called every frame. 'delta' is the elapsed time since the previous frame.
diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd
index 1e18792..fce0783 100644
--- a/server/entities/characters/player.gd
+++ b/server/entities/characters/player.gd
@@ -126,21 +126,17 @@ func _physics_process(delta:float):
 
 
 # Called from the game script to update the vars
-func getPlayerInputs(movementInput:int, jumpInput:bool, jumpId:int,
-attackTypeInput:int, mouseX:int, mouseY:int):
-	motion = 0
+func getPlayerInputs(movementInput:int, jumpId:int, attackTypeInput:int, mouseX:int, mouseY:int):
 	# Prevent the player from moving when attacking
 	if isAttacking:
 		return
 
 	motion = movementInput
-	isJumping = false
 
 	# Differentiate a new jump from a reemitted one
 	if lastJumpId != jumpId:
 		lastJumpId = jumpId
-		if jumpInput:
-			isJumping = true
+		isJumping = true
 	
 	# Execute attack
 	if attackTypeInput != NONE:
@@ -192,13 +188,13 @@ func processMovement(delta:float):
 		currentJump = 0
 		# Reset the last striker
 		lastStrikerId = ownId
-
 	elif currentJump == 0 && !isJumping:
 		# Initial jump prevented
 		currentJump = 1
 
 	# Jump attempts computation
 	if isJumping:
+		isJumping = false
 		if currentJump < maxJump:
 			broadcastAnimation(ANIM_JUMP)
 			currentJump += 1
diff --git a/server/levels/test/game.gd b/server/levels/test/game.gd
index d2b18e6..17b8eab 100644
--- a/server/levels/test/game.gd
+++ b/server/levels/test/game.gd
@@ -1,12 +1,11 @@
 extends Node
 
-master func sendPlayerInputs(movementInput:int, jumpInput:bool, jumpId:int,
-attackStateInput:int, mouseX:int, mouseY:int):
+master func sendPlayerInputs(movementInput:int, jumpId:int, attackStateInput:int, mouseX:int, mouseY:int):
 	# Get the input from a client and send it to the matching remote player
 	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, attackStateInput, mouseX, mouseY)
+		jumpId, attackStateInput, mouseX, mouseY)
 
 
 # When the player exits the game area 
-- 
GitLab