aboutsummaryrefslogtreecommitdiffstats
path: root/godot/scenes/Game.gd
diff options
context:
space:
mode:
Diffstat (limited to 'godot/scenes/Game.gd')
-rw-r--r--godot/scenes/Game.gd40
1 files changed, 25 insertions, 15 deletions
diff --git a/godot/scenes/Game.gd b/godot/scenes/Game.gd
index fef2cc8..09acc86 100644
--- a/godot/scenes/Game.gd
+++ b/godot/scenes/Game.gd
@@ -1,7 +1,7 @@
extends Spatial
-const NUM_LEVELS = 9
-const PAR = [5,2,3,4,5,6,7,8,9]
+const NUM_LEVELS = 3
+const PAR = [5,8,10]
# level control
var current_level_id = 0
@@ -10,17 +10,18 @@ var post_game = false
# stroke control
var current_strokes = 0
-var strokes_per_level = [0,0,0,0,0,0,0,0,0]
+var strokes_per_level = [0,0,0]
+
+var scenes = [
+ preload("res://scenes/levels/level1/level1.tscn"),
+ preload("res://scenes/levels/level2/level2.tscn")
+ ]
# Called when the node enters the scene tree for the first time.
func _ready():
- for i in range(NUM_LEVELS):
- levels.append(get_node("/root/Game/Level%d" % (i+1)))
-
current_strokes = 0
- levels[0].show()
-
$JinglePlayer.stream.loop_mode = AudioStreamSample.LOOP_DISABLED
+ load_scene_by_index(0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
@@ -80,19 +81,16 @@ func is_post_game():
func next_level():
post_game = false
-
- levels[current_level_id].hide()
- current_level_id = current_level_id + 1
-
+
+ current_level_id += 1
current_strokes = 0
+ load_scene_by_index(current_level_id)
+
if current_level_id >= NUM_LEVELS:
get_tree().change_scene("res://scenes/levels/MainMenu.tscn")
return
- # load next level
- levels[current_level_id].show()
-
close_scoreboard()
$Evaluation.hide()
@@ -127,3 +125,15 @@ func evaluate_player(strokes, par):
func _on_JinglePlayer_finished():
$BGMPLayer.stream_paused = false
+
+
+func load_scene_by_index(index):
+ # clear level
+ for n in $LoadedLevel.get_children():
+ $LoadedLevel.remove_child(n)
+ n.queue_free()
+
+ # add new level
+ $LoadedLevel
+ var instance = scenes[index].instance()
+ $LoadedLevel.add_child(instance)