@icon("res://misc/icons/alex.png") class_name Character extends Area2D @export var speed = 400 var player_state = Global.CHARACTERSTATES.IDLE_UP var velocity = Vector2.ZERO # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: velocity = Vector2.ZERO # Map animation to player state match player_state: Global.CHARACTERSTATES.WALK_UP: $AnimatedSprite2D.animation = "walk_up" Global.CHARACTERSTATES.WALK_DOWN: $AnimatedSprite2D.animation = "walk_down" Global.CHARACTERSTATES.WALK_RIGHT: $AnimatedSprite2D.animation = "walk_right" Global.CHARACTERSTATES.WALK_LEFT: $AnimatedSprite2D.animation = "walk_left" Global.CHARACTERSTATES.IDLE_UP: $AnimatedSprite2D.animation = "idle_up" Global.CHARACTERSTATES.IDLE_DOWN: $AnimatedSprite2D.animation = "idle_down" Global.CHARACTERSTATES.IDLE_LEFT: $AnimatedSprite2D.animation = "idle_left" Global.CHARACTERSTATES.IDLE_RIGHT: $AnimatedSprite2D.animation = "idle_right" func animate(): if velocity.length() > 0: velocity = velocity.normalized() * speed $AnimatedSprite2D.play() else: $AnimatedSprite2D.stop()