extends Node2D

onready var buttons1 = $Buttons/CenterContainer/VBoxContainer/HBoxContainer2/VBoxContainer
onready var buttons2 = $Buttons/CenterContainer/VBoxContainer/HBoxContainer2/VBoxContainer2

func _ready():
	var next_level = ProjectSettings.get("levels/next_level")
	if next_level > 10:
		next_level = 1
	if next_level > 5:
		buttons2.get_node("Button" + str(next_level)).grab_focus()
	else:
		buttons1.get_node("Button" + str(next_level)).grab_focus()
		
func _physics_process(delta):
	$Node2D/Player1/AnimatedSprite.play("idle")

func go_to_level(level):
	ProjectSettings.set("levels/next_level", level)
	get_tree().change_scene("res://Level.tscn")

func _on_Button1_pressed():
	go_to_level(1)

func _on_Button2_pressed():
	go_to_level(2)

func _on_Button3_pressed():
	go_to_level(3)

func _on_Button4_pressed():
	go_to_level(4)

func _on_Button5_pressed():
	go_to_level(5)

func _on_Button6_pressed():
	go_to_level(6)

func _on_Button7_pressed():
	go_to_level(7)

func _on_Button8_pressed():
	go_to_level(8)

func _on_Button9_pressed():
	go_to_level(9)

func _on_Button10_pressed():
	go_to_level(10)
