extends Node

func _ready() -> void:
	$Fade/Animation.play_backwards("fade")
	$Screen/Background/Floor/EasterEggFixCollision.disabled = false
	$Gui/HiscoreContainer.show()
	%ScoreContainer.hide()

func start_game():
	$Screen/Background/Floor/EasterEggFixCollision.disabled = true
	$Screen/HurdleSpawner.del_all()
	$Gui/EastereggSpawner.del_all()
	$Screen/SpawnTimer.start()
	$Screen/CoinSpawnTimer.start()
	$Screen/LevelUpTimer.start()
	$Screen/Duck.start()
	$Gui/HiscoreContainer.hide()
	%ScoreContainer.show()
	$"/root/Global".gamerunning = true
	$"/root/Global".start.emit()
	$"/root/Global".score = 0
	$"/root/Global".speed = 100
	print("game started")

func _on_level_up_timer_timeout() -> void:
	if $"/root/Global".speed < $"/root/Global".maxspeed:
		$"/root/Global".speed += 10
	$"/root/Global".levelup.emit()

func _score() -> void:
	if not $"/root/Global".gamerunning:
		%ScoreContainer/score.text = ""
	elif $Screen/Duck.alive:
		$"/root/Global".score += 10
		%ScoreContainer/score.text = str($"/root/Global".score)
