diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/audio.gd | 22 | ||||
-rw-r--r-- | scripts/basketball.gd | 3 | ||||
-rw-r--r-- | scripts/mainmenu.gd | 2 |
3 files changed, 26 insertions, 1 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() diff --git a/scripts/basketball.gd b/scripts/basketball.gd index 7616e14..57c211c 100644 --- a/scripts/basketball.gd +++ b/scripts/basketball.gd @@ -103,3 +103,6 @@ func _on_Hoop_score(): if global_variables.score >= phase_increment[2] and global_variables.score < phase_increment[3]: phase = 2 position_changer() + +func _on_body_entered(_body): + $"/root/Audio".impact_noise(abs($"/root/Node2D/Basketball".get_linear_velocity())) diff --git a/scripts/mainmenu.gd b/scripts/mainmenu.gd index 8bd062a..32fe4f5 100644 --- a/scripts/mainmenu.gd +++ b/scripts/mainmenu.gd @@ -4,7 +4,7 @@ func _ready(): if global_variables.startup: global_variables.startup = false $AnnouncerAudio.play() - $"/root/Audio/AudioStreamPlayer".play() + $"/root/Audio/Music".play() func _on_StartButton_pressed(): get_tree().change_scene_to_file("res://scenes/level.tscn") |