Game.gd 419 B

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