35 lines
1.1 KiB
GDScript
35 lines
1.1 KiB
GDScript
class_name AudioManager
|
|
extends Node
|
|
|
|
# When the game starts, play background music
|
|
func _ready():
|
|
if Global.play_background_music:
|
|
play_background_music()
|
|
|
|
func play_chop_sound():
|
|
## Pick one of the chopping sounds randomly
|
|
var chop_sounds = [
|
|
"res://assets/audio/ogg/SFX/Chopping and Mining/chop 1.ogg",
|
|
"res://assets/audio/ogg/SFX/Chopping and Mining/chop 2.ogg",
|
|
"res://assets/audio/ogg/SFX/Chopping and Mining/chop 3.ogg",
|
|
"res://assets/audio/ogg/SFX/Chopping and Mining/chop 4.ogg"
|
|
]
|
|
var random_index = randi() % chop_sounds.size()
|
|
play_sound_effect(chop_sounds[random_index])
|
|
|
|
|
|
func play_sound_effect(sound_path: String):
|
|
var sfx_player = AudioStreamPlayer.new()
|
|
sfx_player.stream = load(sound_path)
|
|
sfx_player.volume_db = -5 # Set volume for sound effects
|
|
add_child(sfx_player)
|
|
sfx_player.play()
|
|
sfx_player.connect("finished", sfx_player.queue_free)
|
|
|
|
func play_background_music():
|
|
var music_player = AudioStreamPlayer.new()
|
|
music_player.stream = load("res://assets/audio/background_music.ogg")
|
|
music_player.volume_db = -10 # Set volume to a comfortable level
|
|
music_player.autoplay = true
|
|
add_child(music_player)
|
|
music_player.play()
|