Many changes
Handle it
This commit is contained in:
parent
bf09402bc5
commit
214e0aa5e0
366 changed files with 24353 additions and 2096 deletions
48
player/scripts/player_movement.gd
Normal file
48
player/scripts/player_movement.gd
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# PlayerMovement.gd
|
||||
extends Resource
|
||||
class_name PlayerMovement
|
||||
|
||||
var player: CharacterBody2D
|
||||
var animated_sprite: AnimatedSprite2D
|
||||
var speed: float = 300.0
|
||||
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 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue