Ver código fonte

Add editor parameter to loop on a level

Useful when you are making a level, you can put the name of the level in
progress in this "Level To Loop" parameter, and every round will be
launched in this level.
DricomDragon 5 anos atrás
pai
commit
5b67f7d666
1 arquivos alterados com 22 adições e 10 exclusões
  1. 22 10
      Game.gd

+ 22 - 10
Game.gd

@@ -8,6 +8,10 @@ var levelScenes = []
 var levelCurrentNode
 var levelIndex = -1
 
+# Used to test a level in creation
+export (String) var levelToLoop
+var levelSceneToLoop
+
 var playerScene = preload("res://Player.tscn")
 var playerActionsLeft = ["p1_left", "p2_left", "p3_left"]
 var playerActionsRight = ["p1_right", "p2_right", "p3_right"]
@@ -16,6 +20,11 @@ func _ready():
 	for k in range(levelNames.size()):
 		levelScenes.append(null)
 
+	if levelToLoop:
+		levelSceneToLoop = load("res://Levels/" + levelToLoop + ".tscn")
+		if !levelSceneToLoop:
+			push_error("Cant't load level " + levelToLoop)
+
 func _unhandled_input(event):
 	if event.is_action("ui_accept") and event.is_pressed():
 		if get_tree().has_group("living"):
@@ -26,25 +35,28 @@ func _unhandled_input(event):
 
 func create_game():
 	# Clear if required
-	if (get_tree().has_group("players")):
+	if get_tree().has_group("players"):
 		var players = get_tree().get_nodes_in_group("players")
 		for p in players:
 			p.queue_free()
-	if (levelCurrentNode):
+	if levelCurrentNode:
 		remove_child(levelCurrentNode)
 		levelCurrentNode.queue_free()
 
-	# Select level
-	levelIndex += 1
+	if levelToLoop:
+		levelCurrentNode = levelSceneToLoop.instance()
+	else:
+		# Select next level
+		levelIndex += 1
+
+		if (levelIndex >= levelScenes.size()):
+			levelIndex = 0
 
-	if (levelIndex >= levelScenes.size()):
-		levelIndex = 0
+		if !levelScenes[levelIndex]:
+			levelScenes[levelIndex] = load(levelNames[levelIndex])
 
-	if !levelScenes[levelIndex]:
-		levelScenes[levelIndex] = load(levelNames[levelIndex])
+		levelCurrentNode = levelScenes[levelIndex].instance()
 
-	# Load level
-	levelCurrentNode = levelScenes[levelIndex].instance()
 	add_child(levelCurrentNode)
 
 	# Retrieve player spawn points