summaryrefslogtreecommitdiff
path: root/scripts/camera.gd
diff options
context:
space:
mode:
authorLogan <logan@cflip.net>2023-04-30 18:51:05 -0600
committerLogan <logan@cflip.net>2023-04-30 18:51:05 -0600
commitf4381c59c1d239400fbd787fe3a5247f0c535460 (patch)
tree8dfc62aaf276e7f8438e96fec4467bcde917d286 /scripts/camera.gd
parentf30fbd753b23be1f71b4bada5e7063ac00215c33 (diff)
Move to Godot 4 and fixes
Diffstat (limited to 'scripts/camera.gd')
-rw-r--r--scripts/camera.gd16
1 files changed, 8 insertions, 8 deletions
diff --git a/scripts/camera.gd b/scripts/camera.gd
index 773ff75..9204a08 100644
--- a/scripts/camera.gd
+++ b/scripts/camera.gd
@@ -1,7 +1,7 @@
extends Camera2D
-onready var basketball = $"../Basketball"
-onready var hoop = $"../Hoop"
+@onready var basketball = $"../Basketball"
+@onready var hoop = $"../Hoop"
func _process(_delta):
if !basketball.waiting_for_shoot:
@@ -16,22 +16,22 @@ func adjust_zoom():
# Min and max widths of the court we want visible on screen at once
var min_width = dist_to_hoop + basketball.drag_radius * 3
var max_width = limit_right - limit_left
-
+
var zoom_level = Vector2(1, 1)
# Zoom out the camera if we need to show more on screen
if min_width > limit_right:
- zoom_level = zoom_level * (min_width / limit_right)
+ zoom_level /= (min_width / limit_right)
# Width of the view when the zoom is set to 1
var view_width = get_viewport().get_visible_rect().size.x
# Fit the zoom level within the max width if needed
# TODO: There should also be a vertical limit
- var max_zoom = float(max_width) / float(view_width)
- zoom_level.x = clamp(zoom_level.x, 1, max_zoom)
- zoom_level.y = clamp(zoom_level.y, 1, max_zoom)
-
+ var max_zoom = float(view_width) / float(max_width)
+ zoom_level.x = clamp(zoom_level.x, max_zoom, 1)
+ zoom_level.y = clamp(zoom_level.y, max_zoom, 1)
+
set_zoom(zoom_level)
func _on_Basketball_reset():