37 lines
872 B
GDScript
37 lines
872 B
GDScript
extends CharacterBody2D
|
|
|
|
@onready var _sprite = $AnimatedSprite2D
|
|
|
|
const GRAVITY: Vector2 = Vector2(0, 9.8)
|
|
const MAX_SPEED: int = 500
|
|
const IMPULSE: int = 80
|
|
const JUMP: int = -400 #TODO: proper jump arch
|
|
|
|
func _ready():
|
|
_sprite.play("idle", 1)
|
|
|
|
#physics and controls
|
|
func _physics_process(_delta) -> void:
|
|
#falling or jumping
|
|
if is_on_floor() and Input.is_action_just_pressed("input_jump"):
|
|
velocity.y = JUMP
|
|
|
|
velocity += GRAVITY
|
|
|
|
var direction = Input.get_axis("input_left", "input_right")
|
|
if direction:
|
|
velocity.x += IMPULSE * direction
|
|
if abs(velocity.x) > MAX_SPEED:
|
|
velocity.x = MAX_SPEED * sign(velocity.x)
|
|
elif velocity.x != 0:
|
|
velocity.x = log(abs(velocity.x)) * sign(velocity.x)
|
|
|
|
move_and_slide()
|
|
|
|
#animation stuff
|
|
func _on_animation_finished() -> void:
|
|
if randf() < 0.2:
|
|
_sprite.play("idle_glance", 2)
|
|
else:
|
|
_sprite.play("idle", 2)
|