extends Area2D

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 health():
	$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_health_area_entered(area):
	if area.has_method("character_move"):
		$rotate_animation.stop()
		$anim.play("take")
		$"/root/main/menu/Sound".health()
		
		Global.health += 1
		
		$death.set_wait_time(0.3)
		$death.start()
	
	if area.has_method("health"):
		count += 1
		health()
	pass


func _on_health_area_exited(area):
	if area.has_method("health"):
		count -= 1
		health()
	pass
