From d5c6407dd82aaf5fee0c0a6f8d02ff1e9f41df23 Mon Sep 17 00:00:00 2001 From: Logan Date: Sat, 24 Sep 2022 14:06:05 -0600 Subject: Prevent over-scoring with basketball. --- scripts/basketball.gd | 1 + scripts/global_variables.gd | 1 + scripts/hoop.gd | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/basketball.gd b/scripts/basketball.gd index d88d815..8eaa2ba 100644 --- a/scripts/basketball.gd +++ b/scripts/basketball.gd @@ -43,5 +43,6 @@ func _input(event): apply_impulse(Vector2(10, 10), Vector2(x_power, y_power)) is_reset = false else: + global_variables.has_scored = false gravity_scale = 0 do_reset = true diff --git a/scripts/global_variables.gd b/scripts/global_variables.gd index b570635..f0702e6 100644 --- a/scripts/global_variables.gd +++ b/scripts/global_variables.gd @@ -1,3 +1,4 @@ extends Node var score = 0 +var has_scored = false diff --git a/scripts/hoop.gd b/scripts/hoop.gd index 94b3069..87af280 100644 --- a/scripts/hoop.gd +++ b/scripts/hoop.gd @@ -3,5 +3,8 @@ extends StaticBody2D signal score func _on_Area2D_body_exited(_body): - global_variables.score += 1 - emit_signal ("score") + # Prevent scoring multiple points with one basketball throw. + if !global_variables.has_scored: + global_variables.score += 1 + emit_signal ("score") + global_variables.has_scored = true -- cgit v1.2.3