53 lines
1.0 KiB
GDScript
53 lines
1.0 KiB
GDScript
extends NodeState
|
|
|
|
@export var player: Player
|
|
@export var animatedSprite2D: AnimatedSprite2D
|
|
|
|
const jumpGravity = player.GRAVITY
|
|
|
|
@onready var dashSpeed: float = player.dashSpeed
|
|
@onready var jumpHight: float = player.jumpHight
|
|
|
|
var dashTime: float = .2
|
|
var dashDone: bool = false
|
|
var canDash: bool = true
|
|
|
|
@warning_ignore("unused_parameter")
|
|
func on_process(delta: float) -> void:
|
|
pass
|
|
|
|
@warning_ignore("unused_parameter")
|
|
func on_phyisics_process(delta: float) -> void:
|
|
|
|
|
|
player.velocity.y += jumpGravity * delta
|
|
|
|
var direction = -1 if animatedSprite2D.flip_h else 1
|
|
|
|
if direction:
|
|
player.velocity.x =+ dashSpeed * direction
|
|
|
|
transition_states()
|
|
|
|
func enter() -> void:
|
|
player.canDash = false
|
|
dashDone = false
|
|
animatedSprite2D.play("Fall")
|
|
await get_tree().create_timer(dashTime).timeout
|
|
dashDone = true
|
|
|
|
func exit() -> void:
|
|
animatedSprite2D.stop()
|
|
|
|
func transition_states() -> void:
|
|
|
|
if not dashDone:
|
|
return
|
|
|
|
if player.is_on_floor():
|
|
transition.emit("idle")
|
|
|
|
if not player.is_on_floor():
|
|
transition.emit("fall")
|
|
|