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()

View File

@@ -0,0 +1 @@
uid://brqcdlh20sky0

View File

@@ -0,0 +1,33 @@
extends Character
var screen_size
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
screen_size = get_viewport_rect().size
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
super._process(delta)
# Read keyboard input and adjust player state
if Input.is_action_pressed("move_right"):
player_state = Global.CHARACTERSTATES.WALK_RIGHT
velocity.x += 1
elif Input.is_action_pressed("move_left"):
player_state = Global.CHARACTERSTATES.WALK_LEFT
velocity.x -= 1
elif Input.is_action_pressed("move_down"):
player_state = Global.CHARACTERSTATES.WALK_DOWN
velocity.y += 1
elif Input.is_action_pressed("move_up"):
player_state = Global.CHARACTERSTATES.WALK_UP
velocity.y -= 1
else:
match(player_state):
Global.CHARACTERSTATES.WALK_RIGHT: player_state = Global.CHARACTERSTATES.IDLE_RIGHT
Global.CHARACTERSTATES.WALK_LEFT: player_state = Global.CHARACTERSTATES.IDLE_LEFT
Global.CHARACTERSTATES.WALK_UP: player_state = Global.CHARACTERSTATES.IDLE_UP
Global.CHARACTERSTATES.WALK_DOWN: player_state = Global.CHARACTERSTATES.IDLE_DOWN
super.animate()

View File

@@ -0,0 +1 @@
uid://jknm77cuss33