added sounds to ui and game, prepared interaction with character
This commit is contained in:
parent
b5ace17da9
commit
21d7cf417a
42 changed files with 450 additions and 155 deletions
39
globals/sound_manager.gd
Normal file
39
globals/sound_manager.gd
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
extends Node
|
||||
|
||||
@export var music: Array[SoundFile]
|
||||
@export var sfx: Array[SoundFile]
|
||||
const FALLBACK: AudioStream = preload("res://assets/sounds/sfx/fallback.wav")
|
||||
|
||||
@onready var background_music_player: AudioStreamPlayer = %BackgroundMusicPlayer
|
||||
var current_background_music: SoundFile = null
|
||||
|
||||
func play_background_music(resource_name: String) -> void:
|
||||
var sound_file: SoundFile = get_sound_file_resource(resource_name, music)
|
||||
|
||||
background_music_player.stream = sound_file.file
|
||||
background_music_player.play()
|
||||
current_background_music = sound_file
|
||||
|
||||
func play_sound_effect(resource_name: String, p_bus: String = "SFX") -> void:
|
||||
var sound_file: SoundFile = get_sound_file_resource(resource_name, sfx)
|
||||
|
||||
# Create a new unlocalized sound effect
|
||||
var sfx_player: AudioStreamPlayer = AudioStreamPlayer.new()
|
||||
sfx_player.bus = p_bus
|
||||
sfx_player.stream = sound_file.file
|
||||
sfx_player.finished.connect(sfx_player.queue_free)
|
||||
|
||||
self.add_child(sfx_player)
|
||||
sfx_player.play()
|
||||
|
||||
func get_sound_file_resource(_name: String, array: Array) -> Variant:
|
||||
for sound_file: SoundFile in array:
|
||||
if sound_file.name == _name:
|
||||
return sound_file
|
||||
|
||||
# No sound file with the specified name could be found. Oops!
|
||||
push_warning("No Sound effect named \"%s\" could be found." % _name)
|
||||
var oops: SoundFile = SoundFile.new()
|
||||
oops.file = FALLBACK
|
||||
|
||||
return oops
|
||||
Loading…
Add table
Add a link
Reference in a new issue