Create character and player scripts, import character tilesets

This commit is contained in:
2026-03-27 17:56:45 +01:00
parent 41e86c99da
commit 1a306b53a4
18 changed files with 718 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
@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()