H2Grow/Scripts/Player.gd
2024-03-17 13:43:20 +01:00

27 lines
618 B
GDScript

extends KinematicBody2D
var speed = 35;
var velocity = Vector2()
func _ready():
pass
func _physics_process(delta):
velocity = Vector2()
if Input.is_action_pressed("down"):
velocity.y += speed
if Input.is_action_pressed("up"):
velocity.y -= speed
if Input.is_action_pressed("left"):
velocity.x -= speed
if Input.is_action_pressed("right"):
velocity.x += speed
if Input.is_action_pressed("right") || Input.is_action_pressed("left") \
|| Input.is_action_pressed("up") || Input.is_action_pressed("down"):
$AnimationPlayer.play("Walk")
else:
$AnimationPlayer.stop()
move_and_slide(velocity)