Game.gd 472 B

123456789101112131415161718192021
  1. extends Node2D
  2. onready var cam = $Grid/Camera1
  3. var player = []
  4. var dist_max = 900
  5. var zoom_rate = 0.001
  6. func _ready():
  7. player.append($Grid/Player1)
  8. player.append($Grid/Player2)
  9. func _process(d):
  10. cam.position = 0.5 * (player[0].position + player[1].position)
  11. var dist = (player[0].position).distance_to(player[1].position)
  12. if dist < dist_max:
  13. cam.zoom = Vector2(1.0, 1.0)
  14. else:
  15. var zoom = 1.0 + (dist - dist_max) * zoom_rate
  16. cam.zoom = Vector2(zoom, zoom)