extends StateAnimatedActor

export (NodePath) var fall_node
export (NodePath) var idle_node

onready var fall_state: State = get_node(fall_node)
onready var idle_state: State = get_node(idle_node)

var speed_decay_rate := 1.0

func enter():
	remove_animation_state_modifiers()
	.enter()
	

func process_physics(delta: float) -> State:

#	if move_component.wants_shoot():
#		return attack_state
		
	if speed_multiplier > 1.0:
		#print(speed_multiplier,", ", delta)
		speed_multiplier -= delta * speed_decay_rate
		speed_decay_rate += delta
	elif speed_multiplier < 1.0:
		speed_multiplier += delta * speed_decay_rate
		speed_decay_rate += delta
	
	# Deadzone
	if speed_multiplier < 1.1 and speed_multiplier > 0.9:
		speed_multiplier = 1.0

	move_component.velocity.y += gravity * delta
	#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
	#print(speed_multiplier)
	move_component.velocity.x = parent.transform.x.x * move_speed * speed_multiplier
	move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
	
	if animations.frame >= 10:
		#print("WTF - ", animations.frame, " ,", move_component.velocity.x)
		if !parent.is_on_floor():
			return fall_state
		else:
			return idle_state

	return null
