43 lines
1.3 KiB
GDScript
43 lines
1.3 KiB
GDScript
extends KinematicBody2D
|
|
|
|
const MAX_SPEED = 200
|
|
const ACCELERATION = 1000
|
|
const FRICTION = 1000
|
|
const MAX_LIFE = 30
|
|
|
|
var vel = Vector2.ZERO
|
|
var curLife = MAX_LIFE
|
|
|
|
#onready var animationPlayer = $AnimationPlayer
|
|
#onready var animationTree = $AnimationTree
|
|
#onready var animationState = animationTree.get("parameters/playback")
|
|
|
|
func _process(delta):
|
|
curLife -= delta
|
|
if curLife <= 0:
|
|
#fin du game laul
|
|
pass
|
|
|
|
func _physics_process(delta):
|
|
var input_vector = Vector2.ZERO
|
|
|
|
if self.name == "Player1":
|
|
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
|
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
|
elif self.name == "Player2":
|
|
input_vector.x = Input.get_action_strength("ui_right2") - Input.get_action_strength("ui_left2")
|
|
input_vector.y = Input.get_action_strength("ui_down2") - Input.get_action_strength("ui_up2")
|
|
|
|
input_vector = input_vector.normalized()
|
|
|
|
if input_vector != Vector2.ZERO:
|
|
# animationTree.set("parameters/Idle/blend_position", input_vector)
|
|
# animationTree.set("parameters/Run/blend_position", input_vector)
|
|
# animationState.travel("Run")
|
|
vel = vel.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
|
else:
|
|
# animationState.travel("Idle")
|
|
vel = vel.move_toward(Vector2.ZERO, FRICTION * delta)
|
|
|
|
vel = move_and_slide(vel)
|