extends StateAnimatedActor

export (NodePath) var idle_node

onready var idle_state: State = get_node(idle_node)

var flip_flop:bool = false
var recoil_velocity = Vector2.ZERO
var max_recoil:float = 8.0

func enter() -> void:
	.enter()
#	parent.set_hurtbox(true)
	if debug_state:
		print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
	state_timeout.start()


func process_physics(delta: float) -> State:

	if state_timeout.time_left == 0:
		if flip_flop:
			move_component.velocity.y = move_speed
			flip_flop = false
			return idle_state
		else:
			move_component.velocity.y = move_speed * - 1
			flip_flop = true
			return idle_state
	
	#move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
	#var collision = parent.move_and_collide(move_component.velocity * delta, true, true, true)
#	var collision = parent.move_and_collide(Vector2.UP, true, true, true)
#
#	if collision and recoil_velocity == Vector2.ZERO:
#		print("Get off me!")
#		recoil_velocity.y += max_recoil * delta

	
#	if collision and recoil_velocity == Vector2.ZERO:
#		print("Get off me!")
#		recoil_velocity.y += max_recoil * delta
#	else:
#		if recoil_velocity.y < max_recoil:
#			recoil_velocity.y -= max_recoil * delta
#		else:
#			recoil_velocity.y += max_recoil * delta
#		if recoil_velocity.y < 0:
#			recoil_velocity = Vector2.ZERO
			
	#parent.global_translate(move_component.velocity * delta)
	
	parent.position += (move_component.velocity + recoil_velocity) * delta
	
	return null
