From 533a52b11a0e89b2646f9d507432c92d4f552e78 Mon Sep 17 00:00:00 2001 From: tpart Date: Mon, 1 Jul 2024 13:28:07 +0200 Subject: Add footstep sounds to character --- client/audio/play_random.gd | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 client/audio/play_random.gd (limited to 'client/audio') diff --git a/client/audio/play_random.gd b/client/audio/play_random.gd new file mode 100644 index 00000000..1efced30 --- /dev/null +++ b/client/audio/play_random.gd @@ -0,0 +1,41 @@ +# Undercooked - a game about cooking +# Copyright 2024 tpart +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +extends Node +class_name PlayRandom + +@onready var sounds = get_children() + +var autoplay := false + +func _ready(): + for s in sounds: + s.connect("finished", sound_finished) + +func play_random(): + var s = sounds[randi_range(0, sounds.size() - 1)] + s.pitch_scale = randf_range(0.9, 1.1) + s.play() + +func start_autoplay(): + autoplay = true + play_random() + +func stop_autoplay(): + autoplay = false + +func sound_finished(): + if autoplay: + play_random() -- cgit v1.2.3-70-g09d2 From b275180aae28fa37658507454cfeb45ba5799fe4 Mon Sep 17 00:00:00 2001 From: tpart Date: Mon, 1 Jul 2024 14:08:54 +0200 Subject: Add volume and autteniations control to PlayRandom --- client/audio/play_random.gd | 11 +++++++++-- client/player/character/character.tscn | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'client/audio') diff --git a/client/audio/play_random.gd b/client/audio/play_random.gd index 1efced30..afdf046f 100644 --- a/client/audio/play_random.gd +++ b/client/audio/play_random.gd @@ -16,13 +16,20 @@ extends Node class_name PlayRandom -@onready var sounds = get_children() +@export var volume_db := 0.0 +@export var enable_attenuations := true var autoplay := false +@onready var sounds = get_children() + func _ready(): - for s in sounds: + for s: AudioStreamPlayer3D in sounds: s.connect("finished", sound_finished) + s.volume_db = volume_db + + if not enable_attenuations: + s.attenuation_filter_cutoff_hz = 20500 func play_random(): var s = sounds[randi_range(0, sounds.size() - 1)] diff --git a/client/player/character/character.tscn b/client/player/character/character.tscn index 3bea6100..571f8397 100644 --- a/client/player/character/character.tscn +++ b/client/player/character/character.tscn @@ -663,25 +663,25 @@ scale_amount_curve = SubResource("Curve_7ml8g") [node name="Steps" type="Node" parent="."] script = ExtResource("14_3rb6x") +volume_db = -8.0 +enable_attenuations = false [node name="Step1" type="AudioStreamPlayer3D" parent="Steps"] stream = ExtResource("10_qpd6x") -volume_db = -8.0 [node name="Step2" type="AudioStreamPlayer3D" parent="Steps"] stream = ExtResource("11_2dmo8") -volume_db = -8.0 [node name="Step3" type="AudioStreamPlayer3D" parent="Steps"] stream = ExtResource("12_bj5ue") -volume_db = -8.0 [node name="Boosts" type="Node" parent="."] script = ExtResource("14_3rb6x") +volume_db = -12.0 +enable_attenuations = false [node name="Woosh1" type="AudioStreamPlayer3D" parent="Boosts"] stream = ExtResource("14_ikcec") -volume_db = -8.0 [node name="Woosh2" type="AudioStreamPlayer3D" parent="Boosts"] stream = ExtResource("15_iv4wu") -- cgit v1.2.3-70-g09d2