gmtk-2024/player.gd

39 lines
852 B
GDScript3
Raw Normal View History

2024-08-17 14:22:33 +00:00
extends CharacterBody2D
@export var SPEED = 300
@export var GRAVITY = 30
@export var JUMP_FORCE = 500
@onready var animated_sprite = $AnimatedSprite2D;
var jumping = false;
func _ready():
animated_sprite.play("idle")
2024-08-17 14:22:33 +00:00
func _physics_process(delta):
if !is_on_floor():
velocity.y += GRAVITY
if velocity.y > 1000:
velocity.y = 1000
if jumping && is_on_floor():
jumping = false
2024-08-17 14:22:33 +00:00
if Input.is_action_just_pressed("jump") && is_on_floor():
velocity.y = -JUMP_FORCE
jumping = true
animated_sprite.play("jump")
2024-08-17 14:22:33 +00:00
var horizontal_direction = Input.get_axis("move_left", "move_right")
velocity.x = SPEED * horizontal_direction
move_and_slide()
animated_sprite.flip_h = horizontal_direction < 0
if !jumping:
if is_on_floor() && horizontal_direction != 0:
animated_sprite.play("walk")
else:
animated_sprite.play("idle")