super_space_game/scripts/player_ground.gd

31 lines
804 B
GDScript3
Raw Normal View History

2025-12-02 19:51:40 +00:00
extends CharacterBody2D
2025-12-04 03:30:37 +00:00
## Is the player busy in an interaction?
var busy = false
func _ready() -> void:
$Sprite.play()
2025-12-02 19:51:40 +00:00
func _process(delta: float) -> void:
var horizontial_movement = Input.get_axis("ground_left", "ground_right")
var vertical_movement = Input.get_axis("ground_up", "ground_down")
2025-12-04 03:30:37 +00:00
if busy:
velocity = Vector2()
else:
velocity = Vector2(256 * horizontial_movement, 256 * vertical_movement)
if horizontial_movement > 0.1:
$Sprite.scale.x = -2
if horizontial_movement < -0.1:
$Sprite.scale.x = 2
if velocity.length() > 8:
$Sprite.animation = "walk"
if abs(horizontial_movement) > abs(vertical_movement): $Sprite.speed_scale = abs(horizontial_movement)
else: $Sprite.speed_scale = abs(vertical_movement)
else:
$Sprite.animation = "idle"
2025-12-02 19:51:40 +00:00
move_and_slide()