Cranberry/Actors/Player.gd

42 lines
1.5 KiB
GDScript

extends KinematicBody2D
export var MAX_SPEED = 300
var movement = Vector2.ZERO
#var pushing = 0
onready var animationPlayer = $AnimationPlayer
func _physics_process(_delta):
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("Right") - Input.get_action_strength("Left")
input_vector.y = Input.get_action_strength("Down") - Input.get_action_strength("Up")
if (input_vector.x == 1 and input_vector.y == 0):
rotation_degrees = 0
animationPlayer.play("straight")
elif(input_vector.x == -1 and input_vector.y == 0):
rotation_degrees = 180
animationPlayer.play("straight")
elif (input_vector.x == 0 and input_vector.y == 1):
rotation_degrees = 90
animationPlayer.play("straight")
elif(input_vector.x == 0 and input_vector.y == -1):
rotation_degrees = 270
animationPlayer.play("straight")
elif(input_vector.x == 1 and input_vector.y == 1):
rotation_degrees = 90
animationPlayer.play("diagonal")
elif (input_vector.x == 1 and input_vector.y == -1):
rotation_degrees = 0
animationPlayer.play("diagonal")
elif(input_vector.x == -1 and input_vector.y == 1):
rotation_degrees = 180
animationPlayer.play("diagonal")
elif(input_vector.x == -1 and input_vector.y == -1):
rotation_degrees = 270
animationPlayer.play("diagonal")
else:
animationPlayer.play("stop")
input_vector = input_vector.normalized()
movement.x = input_vector.x * MAX_SPEED #* delta
movement.y = input_vector.y * MAX_SPEED #* delta
movement = move_and_slide(movement)