extends Node2D


var count = 1

func _ready():
	$rotate_animation.play("rotation")
	$anim.play("ready")
	
	$death.set_wait_time(8)
	$death.start()
	pass


# warning-ignore:unused_argument
func _physics_process(delta):
	if Global.game_over == true:
		queue_free()
	pass



func gear():
	$Label.set_text(str(count))
	if count <= 1:
			$Label.set_text(str(""))
	pass


func _on_death_timeout():
	queue_free()
	pass


func _on_animation_timeout():
	$anim.play("timeout")
	pass


func _on_gear_area_entered(area):
	if area.has_method("character_move"):
		$rotate_animation.stop()
		$anim.play("take")
		$"/root/main/menu/Sound".gear()
		
		Global.progress += 10
		Global.score += 3
		
		$death.set_wait_time(0.3)
		$death.start()
	
	if area.has_method("gear"):
		count += 1
		gear()
	pass


func _on_gear_area_exited(area):
	if area.has_method("gear"):
		count -= 1
		gear()
	pass
