Prechádzať zdrojové kódy

Make the level list editable in the editor

DricomDragon 4 rokov pred
rodič
commit
8ef2b44ded
2 zmenil súbory, kde vykonal 12 pridanie a 7 odobranie
  1. 11 7
      Game.gd
  2. 1 0
      Game.tscn

+ 11 - 7
Game.gd

@@ -3,15 +3,15 @@ extends Node2D
 onready var cam = $MainCamera
 onready var timer = $StartTimer
 
-var levelNames = ["res://Levels/Focus.tscn", "res://Levels/Lab.tscn", "res://Levels/Square.tscn"]
-var levelScenes = []
-var levelCurrentNode
-var levelIndex = -1
-
 # Used to test a level in creation
 export (String) var levelToLoop
 var levelSceneToLoop
 
+export (Array, String) var levelNames = ["Square"]
+var levelScenes = []
+var levelCurrentNode
+var levelIndex = -1
+
 var playerScene = preload("res://Player.tscn")
 var playerActionsLeft = ["p1_left", "p2_left", "p3_left"]
 var playerActionsRight = ["p1_right", "p2_right", "p3_right"]
@@ -21,10 +21,14 @@ func _ready():
 		levelScenes.append(null)
 
 	if levelToLoop:
-		levelSceneToLoop = load("res://Levels/" + levelToLoop + ".tscn")
+		levelSceneToLoop = load_level(levelToLoop)
 		if !levelSceneToLoop:
 			push_error("Cant't load level " + levelToLoop)
 
+func load_level(name):
+	var fullName = "res://Levels/" + name + ".tscn"
+	return load(fullName)
+
 func _unhandled_input(event):
 	if event.is_action("ui_accept") and event.is_pressed():
 		if get_tree().has_group("living"):
@@ -53,7 +57,7 @@ func create_game():
 			levelIndex = 0
 
 		if !levelScenes[levelIndex]:
-			levelScenes[levelIndex] = load(levelNames[levelIndex])
+			levelScenes[levelIndex] = load_level(levelNames[levelIndex])
 
 		levelCurrentNode = levelScenes[levelIndex].instance()
 

+ 1 - 0
Game.tscn

@@ -5,6 +5,7 @@
 
 [node name="Game" type="Node2D"]
 script = ExtResource( 3 )
+levelNames = [ "Square", "Lab", "Focus" ]
 
 [node name="MainCamera" type="Camera2D" parent="."]
 position = Vector2( 500, -500 )