diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-01 15:48:08 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-01 15:48:08 +0200 |
commit | f4896e35bf204f7b0d0c9766b912cc731cb3f355 (patch) | |
tree | 489bf441641149449a90b2c8194c0ee2416584d8 /client/audio | |
parent | 69cce2c92e067595d862c479104df6e966a1e8ee (diff) | |
parent | 5fc93e0f3fe710f5cad7e3e67dbf6d0a8d600753 (diff) | |
download | hurrycurry-f4896e35bf204f7b0d0c9766b912cc731cb3f355.tar hurrycurry-f4896e35bf204f7b0d0c9766b912cc731cb3f355.tar.bz2 hurrycurry-f4896e35bf204f7b0d0c9766b912cc731cb3f355.tar.zst |
Merge branch 'master' of https://codeberg.org/metamuffin/undercooked
Diffstat (limited to 'client/audio')
-rw-r--r-- | client/audio/play_random.gd | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/client/audio/play_random.gd b/client/audio/play_random.gd new file mode 100644 index 00000000..afdf046f --- /dev/null +++ b/client/audio/play_random.gd @@ -0,0 +1,48 @@ +# 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 <https://www.gnu.org/licenses/>. +# +extends Node +class_name PlayRandom + +@export var volume_db := 0.0 +@export var enable_attenuations := true + +var autoplay := false + +@onready var sounds = get_children() + +func _ready(): + 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)] + 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() |