summaryrefslogtreecommitdiff
path: root/Global.gd
blob: d9414c85bbe54717642977b85e6aa8b381c2c8d4 (plain)
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
extends Node


const Levels = [
	"Level_0001",
	"Level_0001",
	"Level_0001",
	"Level_0001",
	"Level_0001",
	"Level_0001",
	"Level_0001",
	"Level_0001",
	"Level_0001",
]

var Level_Map = []


func _ready():
	for level in self.Levels:
		self.Level_Map.push_back({
			time = 0,
			cleared_by = -1,
			meta = {
				path = "res://Levels/%s.tscn" % level,
				name = level,
			},
		})


func change_scene_to_instance(instance):
	call_deferred("_deferred_change_scene_to_instance", instance)
func _deferred_change_scene_to_instance(instance):
	get_tree().current_scene.free()
	get_tree().get_root().add_child(instance)
	get_tree().set_current_scene(instance)


func get_level(idx):
	return self.Level_Map[idx]


func start_level(idx):
	var global_level = self.get_level(idx)
	
	var Level = load(global_level.meta.path)
	var instance_level = Level.instance()
	instance_level.idx = idx
	self.change_scene_to_instance(instance_level)


func end_level(instance_level):
	var global_level = self.get_level(instance_level.idx)
	
	var time = stepify(instance_level.timer, 0.01)
	if (global_level.time == 0 or time < global_level.time):
		global_level.time = time
		global_level.cleared_by = randi() & 1
	
	get_tree().change_scene("res://UI/LevelSelect.tscn")