-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.gd
58 lines (53 loc) · 1.41 KB
/
Game.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
extends Node
var blocks = []
var columns = 8
var rows = 4
onready var block = preload("res://Block/Block.tscn")
var level_queue=[]
var no_level = 0
func _ready():
randomize()
var _dir = Directory.new()
if _dir.open("res://Level")==OK:
_dir.list_dir_begin()
var file = _dir.get_next()
while file !="":
file = _dir.get_next()
if (file.begins_with("Level") or file.begins_with("Random")) and file.ends_with(".gd"):
if file != "_temp.gd":
level_queue.append(file)
level_queue.sort_custom(self,"sort_levels")
_dir.list_dir_end()
load_level("res://Level/"+level_queue[0])
func load_level(path):
for i in get_children():
if i.get_name() == "Level":
get_node("Level").free()
var _l = preload("res://Level/Level.tscn").instance()
_l.set_name("Level")
_l.set_script(load(path))
add_child(_l,true)
func sort_levels(a,b):
if b.begins_with("Random"):
return(true)
elif a.begins_with("Random"):
return(false)
else:
var as = load("res://Level/"+a)
var bs = load("res://Level/"+b)
var oa = Node.new()
var ob = Node.new()
oa.set_script(as)
ob.set_script(bs)
if oa.difficulty >= ob.difficulty:
return(true)
else:
return(false)
func _on_ball_lost():
if no_level <= level_queue.size():
if no_level < level_queue.size()-1:
no_level += 1
load_level("res://Level/"+level_queue[no_level])
for i in get_node("Level").get_children():
if i.get_name().begins_with("Box"):
i.queue_free()