34 lines
1.2 KiB
GDScript
34 lines
1.2 KiB
GDScript
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()
|