-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.gd
63 lines (44 loc) · 1.14 KB
/
Main.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
extends Node
const MENU_SCENE = "res://ui/Menu.tscn"
const GAME_SCENE_TEMPLATE = "res://levels/level-"
const Menu = preload(MENU_SCENE)
var menu_node = null
var level_node = null
func _ready():
randomize()
open_menu()
func quit_game():
get_tree().quit(0)
func new_game():
open_level("01");
func open_menu():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
unload_level()
menu_node = Menu.instance()
menu_node.connect("quit", self, "quit_game")
menu_node.connect("start", self, "new_game")
add_child(menu_node)
func open_level(level):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
unload_menu()
level_node = load(GAME_SCENE_TEMPLATE + level + ".tscn").instance()
level_node.connect("quit", self, "open_menu")
level_node.connect("win", self, "win")
level_node.connect("loose", self, "loose")
add_child(level_node)
func loose():
open_menu()
menu_node.loose()
func win():
open_menu()
menu_node.win()
func unload_level():
if level_node != null:
remove_child(level_node)
level_node.queue_free()
level_node = null
func unload_menu():
if menu_node != null:
remove_child(menu_node)
menu_node.queue_free()
menu_node = null