summaryrefslogtreecommitdiff
path: root/scripts/basketball.gd
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-09-26 21:33:39 -0600
committercflip <cflip@cflip.net>2022-09-26 21:33:39 -0600
commitdd85ab9413cd7afb533a219420764b9bb0d32a2d (patch)
treea4059ab65296c63f619c19ce9c40089f5a00a865 /scripts/basketball.gd
parent82e8d2eba1811a88a5c86777ed0b0dedfe057cf9 (diff)
Add some comments and minor correctness changes
Diffstat (limited to 'scripts/basketball.gd')
-rw-r--r--scripts/basketball.gd11
1 files changed, 8 insertions, 3 deletions
diff --git a/scripts/basketball.gd b/scripts/basketball.gd
index 857e991..e0c6b3b 100644
--- a/scripts/basketball.gd
+++ b/scripts/basketball.gd
@@ -5,14 +5,16 @@ export var move_speed = 60
export var power_magnitude = 10
export var drag_radius = 30
-var start_position
+var start_position: Vector2
var is_dragging = false
var waiting_for_shoot = true
-var mouse_over_ball
+var mouse_over_ball = false
func _ready():
start_position = position
+# This function toggles between dragging the ball for a shot and allowing the physics engine to move
+# the ball, setting any necessary properties along the way.
func toggle_mode():
if waiting_for_shoot:
waiting_for_shoot = false
@@ -51,12 +53,15 @@ func _input(event):
$GhostSprite.rotation = $Sprite.rotation
if is_dragging and event is InputEventMouseMotion:
$Sprite.position = event.position - start_position
+
+ # If the mouse pointer is beyond a certain radius, don't move the sprite any further from
+ # the start position while still keeping it at the same angle as the mouse pointer.
var hypot = sqrt(pow($Sprite.position.x, 2) + pow($Sprite.position.y, 2))
if hypot > drag_radius:
var angle = atan2($Sprite.position.y, $Sprite.position.x)
$Sprite.position = Vector2(cos(angle), sin(angle)) * drag_radius
if event.is_action_released("shoot"):
- if !waiting_for_shoot || is_dragging:
+ if !waiting_for_shoot or is_dragging:
toggle_mode()
func _on_InnerShape_mouse_entered():