summaryrefslogtreecommitdiff
path: root/scripts/audio.gd
diff options
context:
space:
mode:
authorLogan <logan@cflip.net>2023-05-15 05:47:18 -0600
committerLogan <logan@cflip.net>2023-05-15 05:47:18 -0600
commit35e5e8560da7b66bb988d0f1fc1db521e6e59bd7 (patch)
tree0bfad3320262ecedeb047bc41294b6b5f8b9808c /scripts/audio.gd
parentaf772345caa9fc3a006f91fbd4ab10fc11fe33c7 (diff)
Added basketball collision sounds and audio system
Diffstat (limited to 'scripts/audio.gd')
-rw-r--r--scripts/audio.gd22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/audio.gd b/scripts/audio.gd
new file mode 100644
index 0000000..97f5df6
--- /dev/null
+++ b/scripts/audio.gd
@@ -0,0 +1,22 @@
+extends Node
+
+const audible_threshold = 5
+const dropoff_threshold = 50
+const max_vol = 0
+const min_vol = -20
+
+func _ready():
+ add_streams("res://sound/basketball/", $SFX/Basketball)
+
+func add_streams(res_directory: String, node: Node):
+ var index = 0
+ for file_name in DirAccess.get_files_at(res_directory):
+ if file_name.ends_with(".ogg"):
+ node.stream.add_stream(index, load(res_directory + file_name), 1)
+ index += 1
+
+func impact_noise(velocity: Vector2):
+ var averaged_velocity = (velocity.x + velocity.y) / 2
+ if velocity.y > audible_threshold:
+ $SFX/Basketball.volume_db = (clamp(averaged_velocity, 0, dropoff_threshold) / dropoff_threshold) * (max_vol - min_vol) + min_vol
+ $SFX/Basketball.play()