a game about throwing hammers made for the github game off
Diffstat (limited to 'autoloads/sound_manager.gd')
-rw-r--r--autoloads/sound_manager.gd23
1 files changed, 23 insertions, 0 deletions
diff --git a/autoloads/sound_manager.gd b/autoloads/sound_manager.gd
new file mode 100644
index 0000000..ae617a7
--- /dev/null
+++ b/autoloads/sound_manager.gd
@@ -0,0 +1,23 @@
+extends Node
+
+const sounds_path = "res://assets/sfx/%s.ogg"
+const sounds := {
+ "step": preload(sounds_path % "step"),
+ "death": preload(sounds_path % "death"),
+ "jump": preload(sounds_path % "jump"),
+ "click": preload(sounds_path % "click"),
+ "throw": preload(sounds_path % "woosh"),
+}
+
+@onready var sound_players := get_children()
+
+
+func play(sound: String, volume_db := 0, pitch_scale := randf() + 0.4):
+ for player in sound_players:
+ if not player.playing:
+ player.pitch_scale = pitch_scale
+ player.volume_db = volume_db
+ player.stream = sounds[sound]
+ player.play()
+ return
+ print("sounds overflow, discrding")