소스 검색

Show every players when all dead

Camera show living players only as long as there is at least one living
player.

If everyone is dead, the camera show every crashed players in order to
allow them to inspect their crash site.
DricomDragon 5 년 전
부모
커밋
4f61cc3513
1개의 변경된 파일16개의 추가작업 그리고 12개의 파일을 삭제
  1. 16 12
      Game.gd

+ 16 - 12
Game.gd

@@ -27,26 +27,30 @@ func _ready():
 	add_child(player)
 
 func _process(d):
-	center_camera()
+	move_camera()
 
-func center_camera():
-	var position_accumulator = Vector2(0.0, 0.0)
-	var players = get_tree().get_nodes_in_group("players")
+func move_camera():
 	var living = get_tree().get_nodes_in_group("living")
 
 	if living.size() == 0:
-		# Keep camera in the last position
-		return
-
-	for p in living:
+		# Show every players
+		var players = get_tree().get_nodes_in_group("players")
+		center_on(players)
+	else:
+		# Show remaining players only
+		center_on(living)
+
+func center_on(players):
+	var position_accumulator = Vector2(0.0, 0.0)
+	for p in players:
 		position_accumulator += p.position
 
-	cam.position = position_accumulator / living.size()
+	cam.position = position_accumulator / players.size()
 
 	var dist = 0
-	for i in range(living.size() - 1):
-		for j in range(i + 1, living.size()):
-			dist = max(dist, living[i].position.distance_to(living[j].position))
+	for i in range(players.size() - 1):
+		for j in range(i + 1, players.size()):
+			dist = max(dist, players[i].position.distance_to(players[j].position))
 
 	# Extend camera zoom if liners are far from each other
 	var zoom = 1.0