Przeglądaj źródła

Switch to next level at each start

DricomDragon 5 lat temu
rodzic
commit
9fc581d3c0
2 zmienionych plików z 80 dodań i 8 usunięć
  1. 22 8
      Game.gd
  2. 58 0
      Levels/Square.tscn

+ 22 - 8
Game.gd

@@ -4,11 +4,16 @@ onready var cam = $MainCamera
 export var dist_max = 900
 export var zoom_rate = 0.001
 
-var level
+var levelNames = ["res://Levels/Lab.tscn", "res://Levels/Square.tscn"]
+var levelScenes = []
+var levelCurrentNode
+var levelIndex = -1
+
 var playerScene = preload("res://Player.tscn")
 
 func _ready():
-	pass
+	for k in range(levelNames.size()):
+		levelScenes.append(null)
 
 func _process(_d):
 	move_camera()
@@ -27,19 +32,28 @@ func start():
 		var players = get_tree().get_nodes_in_group("players")
 		for p in players:
 			p.queue_free()
-	if (level):
-		level.queue_free()
+	if (levelCurrentNode):
+		levelCurrentNode.queue_free()
+
+	# Select level
+	levelIndex += 1
+
+	if (levelIndex >= levelScenes.size()):
+		levelIndex = 0
+
+	if !levelScenes[levelIndex]:
+		levelScenes[levelIndex] = load(levelNames[levelIndex])
 
 	# Load level
-	level = preload("res://Levels/Lab.tscn").instance()
-	add_child(level)
+	levelCurrentNode = levelScenes[levelIndex].instance()
+	add_child(levelCurrentNode)
 
 	# Create players
 	var player
 
 	# Player 1
 	player = playerScene.instance()
-	player.grid = level
+	player.grid = levelCurrentNode
 	player.turn_left_action = "player_1_turn_left"
 	player.turn_right_action = "player_1_turn_right"
 	player.position = Vector2(4 * 64 + 32, 8 * 64 + 32)
@@ -47,7 +61,7 @@ func start():
 
 	# Player 2
 	player = playerScene.instance()
-	player.grid = level
+	player.grid = levelCurrentNode
 	player.turn_left_action = "player_2_turn_left"
 	player.turn_right_action = "player_2_turn_right"
 	player.position = Vector2(6 * 64 + 32, 8 * 64 + 32)

Plik diff jest za duży
+ 58 - 0
Levels/Square.tscn