-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLevelManager.gd
72 lines (53 loc) · 1.64 KB
/
LevelManager.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
64
65
66
67
68
69
70
71
72
extends Node
var current_scene = null
var azerty = true
var current_level = 1
export (int) var MIN_LEVEL = 1
export (int) var MAX_LEVEL = 12
onready var music = get_node("/root/MusicPlayer")
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() - 1)
func _process(delta):
if Input.is_action_just_pressed("menu"):
goto_main_menu()
func goto_main_menu():
music.inGame = false
goto_scene("res://Scenes/MainMenuScene.tscn")
func goto_credit_scene():
music.inGame = false
goto_scene("res://Scenes/CreditsScene.tscn")
func goto_levels_scene():
music.inGame = false
goto_scene("res://Scenes/LevelsScene.tscn")
func goto_options_scene():
music.inGame = false
goto_scene("res://Scenes/OptionsScene.tscn")
func reload_level():
goto_level(current_level)
func goto_level(level):
music.inGame = true
if level < MIN_LEVEL:
goto_level(MIN_LEVEL)
elif level <= MAX_LEVEL:
current_level = level
goto_scene("res://Scenes/Levels/Level" + str(level) + "Scene.tscn")
else:
current_level = MIN_LEVEL
goto_credit_scene()
func goto_next_level():
goto_level(current_level+1)
func goto_scene(path):
print("loading " + path)
call_deferred("_deferred_goto_scene", path)
func _deferred_goto_scene(path):
# It is now safe to remove the current scene
current_scene.free()
# Load the new scene.
var s = ResourceLoader.load(path)
# Instance the new scene.
current_scene = s.instance()
# Add it to the active scene, as child of root.
get_tree().get_root().add_child(current_scene)
# Optionally, to make it compatible with the SceneTree.change_scene() API.
get_tree().set_current_scene(current_scene)