|
@@ -3,6 +3,10 @@ extends Node2D
|
|
|
onready var cam = $MainCamera
|
|
|
onready var start_timer = $StartTimer
|
|
|
|
|
|
+var is_round_won
|
|
|
+signal round_won
|
|
|
+signal arena_removed
|
|
|
+
|
|
|
# Used to test a level in creation
|
|
|
export (String) var levelToLoop
|
|
|
var levelSceneToLoop
|
|
@@ -27,14 +31,18 @@ func _ready():
|
|
|
|
|
|
# Create players
|
|
|
var player
|
|
|
- for k in 2:
|
|
|
+ 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()
|
|
|
add_child(player)
|
|
|
+
|
|
|
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")
|
|
|
|
|
|
func load_level(name):
|
|
|
var fullName = "res://Levels/" + name + ".tscn"
|
|
@@ -53,6 +61,7 @@ func create_game():
|
|
|
if levelCurrentNode:
|
|
|
remove_child(levelCurrentNode)
|
|
|
levelCurrentNode.queue_free()
|
|
|
+ emit_signal("arena_removed")
|
|
|
|
|
|
# Create level node
|
|
|
if levelToLoop:
|
|
@@ -84,5 +93,10 @@ func create_game():
|
|
|
# Delay start
|
|
|
start_timer.start()
|
|
|
|
|
|
-func _on_round_end():
|
|
|
- get_tree().call_group("players", "_on_round_end")
|
|
|
+func _on_player_crash():
|
|
|
+ if get_tree().get_nodes_in_group("running").size() <= 1 and !is_round_won:
|
|
|
+ emit_signal("round_won")
|
|
|
+ is_round_won = true
|
|
|
+
|
|
|
+func _on_start_game():
|
|
|
+ is_round_won = false
|