randomgeon/player/scripts/player_movement.gd
Dan Baker ff62d67f54 Adds in-game debug menu addon
Adds an in-game debug menu that displays performance metrics (FPS, frame times) and hardware/software information.

The menu can be toggled using the F3 key (or a custom input binding). It has different display styles, ranging from a compact FPS display to a detailed view with graphs and system information.
2025-05-04 17:53:46 +01:00

51 lines
1.1 KiB
GDScript

# PlayerMovement.gd
extends Resource
class_name PlayerMovement
var player: CharacterBody2D
var animated_sprite: AnimatedSprite2D
var speed: float
var last_direction: Vector2 = Vector2.ZERO
func process(_delta):
# Get input direction
var direction = Vector2.ZERO
if Input.is_action_pressed("move_right"):
direction.x += 1
if Input.is_action_pressed("move_left"):
direction.x -= 1
if Input.is_action_pressed("move_down"):
direction.y += 1
if Input.is_action_pressed("move_up"):
direction.y -= 1
# Normalize the direction
if direction.length() > 0:
direction = direction.normalized()
last_direction = direction
# Set velocity
player.velocity = direction * speed
# Move the character
player.move_and_slide()
# Update animation
update_animation(direction)
func update_animation(direction):
var anim_name = "idle" # Default animation
if animated_sprite.animation == "throw":
return # Don't change animation if throwing
if direction == Vector2.ZERO:
# Character is idle
anim_name = "idle"
else:
# Character is moving
anim_name = "walk"
if animated_sprite.animation != anim_name:
animated_sprite.play(anim_name)