blob: 97f5df600bec515bb5a62f1618aee7606ece1fda (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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()
|