|
@@ -16,50 +16,51 @@ var levelScenes = []
|
|
|
var levelOldNode
|
|
|
var levelCurrentNode
|
|
|
var levelIndex = -1
|
|
|
-onready var levelSwap = $LevelSwap
|
|
|
|
|
|
-var playerScene = preload("res://Player.tscn")
|
|
|
-var playerActionsLeft = ["p1_left", "p2_left", "p3_left"]
|
|
|
-var playerActionsRight = ["p1_right", "p2_right", "p3_right"]
|
|
|
-export (Array, Color) var playerColors = [Color.red, Color.blue, Color.green, Color.yellow, Color.white, Color.cyan, Color.magenta, Color.orange]
|
|
|
+var _players_connected = false
|
|
|
+
|
|
|
+onready var levelSwap = $LevelSwap
|
|
|
+onready var hub = $Hub
|
|
|
|
|
|
func _ready():
|
|
|
# Prepare levels
|
|
|
for _k in range(levelNames.size()):
|
|
|
levelScenes.append(null)
|
|
|
|
|
|
- levelSwap.connect("tween_completed", self, "_on_swap_completed")
|
|
|
-
|
|
|
if levelToLoop:
|
|
|
levelSceneToLoop = load_level(levelToLoop)
|
|
|
if !levelSceneToLoop:
|
|
|
push_error("Cant't load level " + levelToLoop)
|
|
|
|
|
|
- # Create players
|
|
|
- var player
|
|
|
- for k in 3:
|
|
|
- player = playerScene.instance()
|
|
|
- player.grid = levelCurrentNode
|
|
|
- player.turn_left_action = playerActionsLeft[k]
|
|
|
- player.turn_right_action = playerActionsRight[k]
|
|
|
- player.position = Vector2()
|
|
|
- player.modulate = playerColors[k]
|
|
|
- add_child(player)
|
|
|
+ # Connections
|
|
|
+ levelSwap.connect("tween_completed", self, "_on_swap_completed")
|
|
|
+ hub.connect("hub_finished", self, "_on_hub_finished")
|
|
|
+
|
|
|
+func connect_players():
|
|
|
+ if _players_connected:
|
|
|
+ push_error("Players are already connected!")
|
|
|
+ return
|
|
|
+
|
|
|
+ for player in get_tree().get_nodes_in_group("players"):
|
|
|
|
|
|
start_timer.connect("timeout", player, "_on_round_start")
|
|
|
- player.connect("crash", self, "_on_player_crash")
|
|
|
self.connect("round_won", player, "_on_round_won")
|
|
|
self.connect("arena_removed", player, "_on_arena_removed")
|
|
|
|
|
|
+ player.connect("crash", self, "_on_player_crash")
|
|
|
+
|
|
|
+ _players_connected = true
|
|
|
+
|
|
|
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 is_round_won == null or is_round_won:
|
|
|
+ if is_round_won:
|
|
|
is_round_won = false
|
|
|
create_game()
|
|
|
+ get_tree().set_input_as_handled()
|
|
|
|
|
|
func create_game():
|
|
|
# Clear if required
|
|
@@ -123,3 +124,11 @@ func _on_swap_completed(object, _k):
|
|
|
|
|
|
elif object == levelCurrentNode:
|
|
|
start_timer.start()
|
|
|
+
|
|
|
+func _on_hub_finished():
|
|
|
+ connect_players()
|
|
|
+
|
|
|
+# hub.remove_and_skip()
|
|
|
+ hub = null # TODO : add an argument in connect and remove temporary attribute
|
|
|
+
|
|
|
+ create_game()
|