Skip to content
Snippets Groups Projects
Commit ff98a2de authored by ZERBIB TIMOTHEE's avatar ZERBIB TIMOTHEE
Browse files

Improved attacks

parent 3e306773
Branches
Tags
No related merge requests found
...@@ -5,4 +5,4 @@ puppet func getRemoteMovement(position:Vector3): ...@@ -5,4 +5,4 @@ puppet func getRemoteMovement(position:Vector3):
self.set_translation(position) self.set_translation(position)
puppet func hurt(damages:int): puppet func hurt(damages:int):
print("You suffered a hit and lost "+str(damages)+" HPs !") print("You suffered a hit and lost " + str(damages) + " HPs !")
\ No newline at end of file \ No newline at end of file
...@@ -3,7 +3,7 @@ extends Node ...@@ -3,7 +3,7 @@ extends Node
const GAMEPATH = "/root/game/" const GAMEPATH = "/root/game/"
const PORT = 10001 const PORT = 10001
const MAX_CLIENTS = 2 const MAX_CLIENTS = 1
var players = {} var players = {}
......
...@@ -2,10 +2,8 @@ extends KinematicBody ...@@ -2,10 +2,8 @@ extends KinematicBody
onready var ownId = self.name onready var ownId = self.name
######## MOVEMENT AND POSITION VARS ########
# The side faced by the player ######## MOVEMENT AND POSITION VARS ########
var orientation:int = 1
# Speed values # Speed values
const MAX_SPEED:float = 8.0 const MAX_SPEED:float = 8.0
...@@ -28,18 +26,30 @@ const GRAVITY:float = -28.0 ...@@ -28,18 +26,30 @@ const GRAVITY:float = -28.0
var vel:Vector3 = Vector3() var vel:Vector3 = Vector3()
# move_and_slide need that # move_and_slide need that
const FLOOR_NORMAL:Vector3 = Vector3(0,1,0) const FLOOR_NORMAL:Vector3 = Vector3(0, 1, 0)
######### ATTACKS VARS ########
# l2r ######### ATTACKS VARS ########
var isAttacking:bool = false var isAttacking:bool = false
onready var attackTimer:Tween = $attackTween
# attack type # attack type
enum {NONE=0, PRIMARY=1, SECONDARY=2} enum {NONE=0, PRIMARY=1, SECONDARY=2}
# attacks related nodes
onready var attackTimer:Tween = $attackTween # Primary attack parameters
onready var primaryHitArea:Area = $primaryHitArea onready var primaryHitArea:Area = $primaryHitArea
var primaryAttackDmg:float = 30.0
var primaryAttackDist:float = 1.2
var primaryAttackDuration:float = 0.6
# Secondary attack parameters
onready var secondaryHitArea:Area = $secondaryHitArea onready var secondaryHitArea:Area = $secondaryHitArea
var secondaryAttackDmg:float = 15.0
var secondaryAttackDist:float = 1.2
var secondaryAttackDuration:float = 0.3
######## FUNCTIONS ######## ######## FUNCTIONS ########
...@@ -50,18 +60,26 @@ func _physics_process(delta): ...@@ -50,18 +60,26 @@ func _physics_process(delta):
# Called from the game script to update the vars # Called from the game script to update the vars
func getPlayerInputs(movementInput, sprintInput, jumpInput, attackTypeInput): func getPlayerInputs(movementInput, sprintInput, jumpInput, attackTypeInput):
motion = 0
# Check if the character isn't already attacking
if isAttacking:
return
motion = movementInput motion = movementInput
orientation = movementInput if movementInput!=0 else orientation
isSprinting = sprintInput isSprinting = sprintInput
isJumping = jumpInput isJumping = jumpInput
if !isAttacking && attackTypeInput:
processAttack(attackTypeInput)
if attackTypeInput != NONE:
processAttack(attackTypeInput)
func processMovement(delta): func processMovement(delta):
if orientation == 1: # Set the side faced by the character
set_rotation_degrees(Vector3(0,0,0)) if motion > 0:
else: set_rotation_degrees(Vector3(0, 0, 0))
set_rotation_degrees(Vector3(0,180,0)) elif motion < 0:
set_rotation_degrees(Vector3(0, 180, 0))
if self.is_on_floor(): if self.is_on_floor():
if isJumping: if isJumping:
...@@ -80,7 +98,7 @@ func processMovement(delta): ...@@ -80,7 +98,7 @@ func processMovement(delta):
# Acceleration of the player if he is moving horizontally # Acceleration of the player if he is moving horizontally
var accel:float var accel:float
var hvel:Vector3 = Vector3(vel.x,0,0) var hvel:Vector3 = Vector3(vel.x, 0, 0)
if target.dot(hvel)>0: if target.dot(hvel)>0:
if isSprinting: if isSprinting:
accel = SPRINT_ACCEL accel = SPRINT_ACCEL
...@@ -98,47 +116,49 @@ func processMovement(delta): ...@@ -98,47 +116,49 @@ func processMovement(delta):
# Send the position of the player # Send the position of the player
func broadcastMovement(): func broadcastMovement():
rpc("getRemoteMovement", self.get_translation()) rpc("getRemoteMovement", self.get_translation())
# Check and trigger the type of attack requested # Check and trigger the type of attack requested
func processAttack(attackType): func processAttack(attackType):
isAttacking = true isAttacking = true
match attackType: match attackType:
PRIMARY: PRIMARY:
primaryAttack() primaryAttack()
SECONDARY: SECONDARY:
secondaryAttack() secondaryAttack()
func primaryAttack(): func primaryAttack():
primaryHitArea.set_monitoring(true) primaryHitArea.set_monitoring(true)
primaryHitArea.set_visible(true) primaryHitArea.set_visible(true)
var duration:float = 0.6
var distance:float = 1.2
attackTimer.interpolate_property(primaryHitArea, "translation:x", 0, distance, duration, Tween.TRANS_BACK, Tween.EASE_IN) attackTimer.interpolate_property(primaryHitArea, "translation:x", 0, primaryAttackDist, primaryAttackDuration, Tween.TRANS_BACK, Tween.EASE_IN)
attackTimer.start() attackTimer.start()
yield(attackTimer, "tween_completed") yield(attackTimer, "tween_completed")
primaryHitArea.set_monitoring(false) primaryHitArea.set_monitoring(false)
primaryHitArea.set_visible(false) primaryHitArea.set_visible(false)
isAttacking = false isAttacking = false
func secondaryAttack(): func secondaryAttack():
secondaryHitArea.set_monitoring(true) secondaryHitArea.set_monitoring(true)
secondaryHitArea.set_visible(true) secondaryHitArea.set_visible(true)
var duration:float = 0.3
var distance:float = 1.2
attackTimer.interpolate_property(secondaryHitArea, "translation:x", 0, distance, duration, Tween.TRANS_BACK, Tween.EASE_IN) attackTimer.interpolate_property(secondaryHitArea, "translation:x", 0, secondaryAttackDist, secondaryAttackDuration, Tween.TRANS_BACK, Tween.EASE_IN)
attackTimer.start() attackTimer.start()
yield(attackTimer, "tween_completed") yield(attackTimer, "tween_completed")
secondaryHitArea.set_monitoring(false) secondaryHitArea.set_monitoring(false)
secondaryHitArea.set_visible(false) secondaryHitArea.set_visible(false)
isAttacking = false isAttacking = false
func hurt(damages): func hurt(damages):
rpc_id(int(ownId), "hurt", str(damages)); rpc_id(int(ownId), "hurt", str(damages));
######## SIGNALS ######## ######## SIGNALS ########
# Primary hit has landed on something # Primary hit has landed on something
...@@ -146,13 +166,15 @@ func _on_primaryHitArea_body_entered(body): ...@@ -146,13 +166,15 @@ func _on_primaryHitArea_body_entered(body):
if body.name==ownId: if body.name==ownId:
return return
print("body named "+body.name+" hit: primary") print("body named " + body.name + " hit: primary")
body.hurt(30) body.hurt(primaryAttackDmg)
# Secondary hit has landed on something # Secondary hit has landed on something
func _on_secondaryHitArea_body_entered(body): func _on_secondaryHitArea_body_entered(body):
if body.name==ownId: if body.name==ownId:
return return
print("body named "+body.name+" hit: secondary") print("body named " + body.name + " hit: secondary")
body.hurt(secondaryAttackDmg)
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