extends CanvasLayer


var health


func _ready():
	health = Global.health
	$health/health.play("start")
	pass


func timer_start():
	$gear/energy.start()
	pass

func timer_stop():
	$gear/energy.stop()
	pass


func level_up():
	$text/new_level.play("level_up")
	pass


func health_anim():
	if Global.health < health:
		if Global.health == 2:
			$health/health.play("three_minus_one")
		if Global.health == 1:
			$health/health.play("two_minus_one")
		if Global.health == 0:
			$health/health.play("one_minus_one")
	if Global.health > health:
		if Global.health == 3:
			$health/health.play("two_plus_one")
		if Global.health == 2:
			$health/health.play("one_plus_one")
		if Global.health == 1:
			$health/health.play("zero_plus_one")
	
	health = Global.health
	pass


func progress():
	$gear/progress.max_value = Global.level_progress
	$gear/progress.set_value(Global.progress)
	pass

# warning-ignore:unused_argument
func _physics_process(delta):
	$text/lvl.set_text(str("Lvl:"))
	$text/level.set_text(str(Global.level))
	$text/score.set_text(str("Score:"))
	$text/sc.set_text(str(Global.score))
	
	$gear/progress/Label.set_text(str(Global.progress) + " / " + str(Global.level_progress))
	
	health_anim()
	progress()
	pass


func _on_energy_timeout():
	Global.progress -= 1
	if Global.progress <= 0:
		Global.health -= 1
		Global.progress = 10
	elif Global.progress <= 10:
		$gear/anim.play("low_progress")
	else:
		$gear/anim.play("normal_progress")
	pass
