ソースを参照

Use a group instead of player list

Would be easier later to use virtual callbacks.
DricomDragon 5 年 前
コミット
2059870a9c
2 ファイル変更3 行追加3 行削除
  1. 1 3
      Game.gd
  2. 2 0
      Player.gd

+ 1 - 3
Game.gd

@@ -2,7 +2,6 @@ extends Node2D
 
 onready var cam = $MainCamera
 onready var level = $Grid
-var players = []
 var dist_max = 900
 var zoom_rate = 0.001
 
@@ -17,7 +16,6 @@ func _ready():
 	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)
-	players.append(player) # TODO : use groups
 	add_child(player)
 
 	# Player 2
@@ -26,7 +24,6 @@ func _ready():
 	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)
-	players.append(player) # TODO : use groups
 	add_child(player)
 
 func _process(d):
@@ -35,6 +32,7 @@ func _process(d):
 func center_camera():
 	var living_players = []
 	var position_accumulator = Vector2(0.0, 0.0)
+	var players = get_tree().get_nodes_in_group("players")
 
 	for p in players:
 		if (p.is_alive()):

+ 2 - 0
Player.gd

@@ -37,6 +37,8 @@ export var turn_left_action:String
 export var turn_right_action:String
 
 func _ready():
+	add_to_group("players")
+
 	assert(grid)
 	assert(turn_left_action)
 	assert(turn_right_action)