aboutsummaryrefslogtreecommitdiff
path: root/game/src
diff options
context:
space:
mode:
Diffstat (limited to 'game/src')
-rw-r--r--game/src/Autoload/SFX.gd20
-rw-r--r--game/src/MainMenu/MainMenu.gd5
2 files changed, 25 insertions, 0 deletions
diff --git a/game/src/Autoload/SFX.gd b/game/src/Autoload/SFX.gd
new file mode 100644
index 0000000..5299848
--- /dev/null
+++ b/game/src/Autoload/SFX.gd
@@ -0,0 +1,20 @@
+extends Node
+
+var _loaded_sfx = {}
+
+func _ready():
+ var dir = DirAccess.open("res://audio/sfx/")
+ for fname in dir.get_files():
+ if fname.get_extension() == "ogg":
+ _loaded_sfx[fname.get_basename()] = load("res://audio/sfx/" + fname) # SND-10
+
+# SND-7
+func play(sound):
+ var player = AudioStreamPlayer.new()
+ player.bus = "SFX"
+ player.stream = _loaded_sfx[sound]
+ add_child(player)
+ player.play()
+ await player.finished
+ remove_child(player)
+
diff --git a/game/src/MainMenu/MainMenu.gd b/game/src/MainMenu/MainMenu.gd
index 000dc69..cd333a3 100644
--- a/game/src/MainMenu/MainMenu.gd
+++ b/game/src/MainMenu/MainMenu.gd
@@ -12,23 +12,28 @@ func _ready():
func _on_new_game_button_pressed():
+ SFX.play("click")
print("Start a new game!")
get_tree().change_scene_to_file("res://src/SampleGame.tscn")
func _on_continue_button_pressed():
+ SFX.play("click")
print("Continue last game!")
func _on_multi_player_button_pressed():
+ SFX.play("click")
print("Have fun with friends!")
func _on_options_button_pressed():
+ SFX.play("click")
print("Check out some options!")
options_button_pressed.emit()
func _on_exit_button_pressed():
+ await SFX.play("click")
print("See you later!")
get_tree().quit()