27 lines
675 B
GDScript
27 lines
675 B
GDScript
extends CharacterBody2D
|
|
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
|
var current_xp = 0
|
|
var max_xp =5
|
|
var level = 1
|
|
var speed = 200 # speed in pixels/sec
|
|
|
|
func _physics_process(delta):
|
|
var direction = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
|
velocity = direction * speed
|
|
|
|
if direction == Vector2.ZERO:
|
|
animated_sprite_2d.play("idle")
|
|
elif abs(direction.x) >= abs(direction.y):
|
|
if direction.x < 0:
|
|
animated_sprite_2d.play("walk_left")
|
|
else:
|
|
animated_sprite_2d.play("walk_right")
|
|
else:
|
|
if direction.y < 0:
|
|
animated_sprite_2d.play("walk_up")
|
|
else:
|
|
animated_sprite_2d.play("walk_down")
|
|
|
|
|
|
move_and_slide()
|