diff options
author | Logan <logan@cflip.net> | 2022-09-26 11:43:55 -0600 |
---|---|---|
committer | Logan <logan@cflip.net> | 2022-09-26 11:43:55 -0600 |
commit | 7921365f0608ea6840998c04af7286044f077a84 (patch) | |
tree | 189d183590e9f5091d4a9b47adcd28b0735b4ea5 | |
parent | ec3b1f444db16ebfbbde48e20be3b92500762a57 (diff) |
Made basketball change position based on hoop's position.
-rw-r--r-- | scenes/level.tscn | 4 | ||||
-rw-r--r-- | scripts/basketball.gd | 5 | ||||
-rw-r--r-- | scripts/global_variables.gd | 1 | ||||
-rw-r--r-- | scripts/hoop.gd | 5 |
4 files changed, 10 insertions, 5 deletions
diff --git a/scenes/level.tscn b/scenes/level.tscn index 8dfaa66..fc0d753 100644 --- a/scenes/level.tscn +++ b/scenes/level.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://textures/court_lines.png" type="Texture" id=1] [ext_resource path="res://scenes/hoop.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/basketball.tscn" type="PackedScene" id=3] [ext_resource path="res://scenes/interface.tscn" type="PackedScene" id=4] [ext_resource path="res://textures/court_tile.png" type="Texture" id=5] -[ext_resource path="res://scripts/interface.gd" type="Script" id=6] [sub_resource type="LineShape2D" id=1] d = 10.0 @@ -13,7 +12,6 @@ d = 10.0 [node name="Node2D" type="Node2D"] [node name="Interface" parent="." instance=ExtResource( 4 )] -script = ExtResource( 6 ) [node name="Hoop" parent="." instance=ExtResource( 2 )] position = Vector2( 163, 37 ) diff --git a/scripts/basketball.gd b/scripts/basketball.gd index ea9fe65..522ab2d 100644 --- a/scripts/basketball.gd +++ b/scripts/basketball.gd @@ -91,8 +91,11 @@ func _on_InnerShape_mouse_exited(): func position_changer(): if global_variables.score < 5: + var clamp_minimum; var clamp_maximum + clamp_minimum = $OuterShape/CollisionShape2D.shape.radius + 0 + clamp_maximum = global_variables.hoop_position - 40 start_position.x -= 20 - start_position.x = clamp(start_position.x, 30, 123) + start_position.x = clamp(start_position.x, clamp_minimum, clamp_maximum) else: start_position.x = rand_range(30, 123) diff --git a/scripts/global_variables.gd b/scripts/global_variables.gd index f0702e6..b48e077 100644 --- a/scripts/global_variables.gd +++ b/scripts/global_variables.gd @@ -2,3 +2,4 @@ extends Node var score = 0 var has_scored = false +var hoop_position diff --git a/scripts/hoop.gd b/scripts/hoop.gd index 87af280..dc43cc1 100644 --- a/scripts/hoop.gd +++ b/scripts/hoop.gd @@ -2,9 +2,12 @@ extends StaticBody2D signal score +func _ready(): + global_variables.hoop_position = position.x + func _on_Area2D_body_exited(_body): # Prevent scoring multiple points with one basketball throw. if !global_variables.has_scored: + global_variables.has_scored = true global_variables.score += 1 emit_signal ("score") - global_variables.has_scored = true |