48 lines
1.1 KiB
GDScript
48 lines
1.1 KiB
GDScript
extends State
|
|
|
|
export (NodePath) var idle_node
|
|
export (NodePath) var fall_node
|
|
export (NodePath) var move_node
|
|
|
|
onready var idle_state: State = get_node(idle_node)
|
|
onready var fall_state: State = get_node(fall_node)
|
|
onready var move_state: State = get_node(move_node)
|
|
|
|
|
|
export var jump_force: float = 900.0
|
|
|
|
func enter() -> void:
|
|
.enter()
|
|
parent.velocity.y = -jump_force
|
|
|
|
func process_frame(_delta: float) -> State:
|
|
move_component.get_movement_direction()
|
|
return null
|
|
|
|
|
|
func process_physics(delta: float) -> State:
|
|
parent.velocity.y += gravity * delta
|
|
|
|
if parent.velocity.y > 0:
|
|
return fall_state
|
|
|
|
parent.velocity.x = move_component.desired_movement_vector.x * move_speed
|
|
parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
|
|
if parent.velocity.x > 0:
|
|
parent.direction.x = 1
|
|
elif parent.velocity.x < 0:
|
|
parent.direction.x = -1
|
|
|
|
if move_component.flipped_sprite == true:
|
|
animations.flip_h = parent.direction.x > 0
|
|
else:
|
|
animations.flip_h = parent.direction.x < 0
|
|
|
|
if parent.is_on_floor():
|
|
if parent.velocity.x == 0:
|
|
return move_state
|
|
return idle_state
|
|
|
|
return null
|