extends StateAnimatedActor

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()
	move_component.velocity.y = -jump_force

func process_input(_event: InputEvent) -> State:
	move_component.get_movement_direction()
	return null


func process_physics(delta: float) -> State:
	move_component.velocity.y += gravity * delta
	
	if move_component.velocity.y > 0:
		return fall_state
	
	move_component.velocity.x = move_component.desired_movement_vector.x * move_speed
	move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))

	if move_component.get_movement_direction() != 0.0:
		parent.transform.x.x = move_component.get_movement_direction()

#	if move_component.flipped_sprite == false:
#		#parent.scale.x = parent.direction.x * -1
#		parent.transform.x.x = parent.direction.x * -1 # -1
#	else:
#		#parent.scale.x = parent.direction.x
#		parent.transform.x.x = parent.direction.x # 1
	
	if parent.is_on_floor():
		if move_component.velocity.x == 0:
			return move_state
		return idle_state
	
	return null
