|
@@ -8,12 +8,35 @@ var level
|
|
|
var playerScene = preload("res://Player.tscn")
|
|
|
|
|
|
func _ready():
|
|
|
- var player
|
|
|
+ pass
|
|
|
+
|
|
|
+func _process(_d):
|
|
|
+ move_camera()
|
|
|
+
|
|
|
+func _unhandled_input(event):
|
|
|
+ if event.is_action("ui_accept") and event.is_pressed():
|
|
|
+ if get_tree().has_group("living"):
|
|
|
+ var living = get_tree().get_nodes_in_group("living")
|
|
|
+ if !living.empty():
|
|
|
+ return
|
|
|
+ start()
|
|
|
+
|
|
|
+func start():
|
|
|
+ # Clear if required
|
|
|
+ if (get_tree().has_group("players")):
|
|
|
+ var players = get_tree().get_nodes_in_group("players")
|
|
|
+ for p in players:
|
|
|
+ p.queue_free()
|
|
|
+ if (level):
|
|
|
+ level.queue_free()
|
|
|
|
|
|
# Load level
|
|
|
level = preload("res://Levels/Lab.tscn").instance()
|
|
|
add_child(level)
|
|
|
|
|
|
+ # Create players
|
|
|
+ var player
|
|
|
+
|
|
|
# Player 1
|
|
|
player = playerScene.instance()
|
|
|
player.grid = level
|
|
@@ -29,17 +52,19 @@ func _ready():
|
|
|
player.turn_right_action = "player_2_turn_right"
|
|
|
player.position = Vector2(6 * 64 + 32, 8 * 64 + 32)
|
|
|
add_child(player)
|
|
|
-
|
|
|
+
|
|
|
# TODO Timer
|
|
|
get_tree().call_group("players", "_on_game_start")
|
|
|
|
|
|
-func _process(_d):
|
|
|
- move_camera()
|
|
|
-
|
|
|
func move_camera():
|
|
|
- var living = get_tree().get_nodes_in_group("living")
|
|
|
+ if !get_tree().has_group("players"):
|
|
|
+ return
|
|
|
+
|
|
|
+ var living
|
|
|
+ if get_tree().has_group("living"):
|
|
|
+ living = get_tree().get_nodes_in_group("living")
|
|
|
|
|
|
- if living.size() == 0:
|
|
|
+ if !living or living.size() == 0:
|
|
|
# Show every players
|
|
|
var players = get_tree().get_nodes_in_group("players")
|
|
|
center_on(players)
|