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
|
|
@ -1,5 +1,5 @@
|
|||
extends Resource
|
||||
class_name MusicFile
|
||||
class_name SoundFile
|
||||
|
||||
@export var file: AudioStream
|
||||
@export var name: String
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
extends Node
|
||||
|
||||
@export var music: Array[MusicFile]
|
||||
|
||||
func play(_file: String) -> void:
|
||||
pass
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://boxny6sh3y05y"]
|
||||
|
||||
[ext_resource type="Script" path="res://globals/background_music_manager.gd" id="1_ngng4"]
|
||||
[ext_resource type="Script" path="res://globals/MusicFile.gd" id="2_d24t4"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_rphwp"]
|
||||
script = ExtResource("2_d24t4")
|
||||
name = ""
|
||||
|
||||
[node name="BackgroundMusicManager" type="Node"]
|
||||
script = ExtResource("1_ngng4")
|
||||
music = Array[ExtResource("2_d24t4")]([SubResource("Resource_rphwp")])
|
||||
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
|
||||
19
globals/sound_manager.tscn
Normal file
19
globals/sound_manager.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://boxny6sh3y05y"]
|
||||
|
||||
[ext_resource type="Script" path="res://globals/sound_manager.gd" id="1_n6pv8"]
|
||||
[ext_resource type="Script" path="res://globals/SoundFile.gd" id="2_vxk68"]
|
||||
[ext_resource type="Resource" uid="uid://bva8fufmwcsey" path="res://resources/sounds/unexplored_fields.tres" id="3_f5ali"]
|
||||
[ext_resource type="Resource" uid="uid://cuxdo1enalicx" path="res://resources/sounds/unexpected_fight.tres" id="4_fn62j"]
|
||||
[ext_resource type="Resource" uid="uid://b3j8y8bt76o12" path="res://resources/sounds/battle_win.tres" id="5_tids3"]
|
||||
[ext_resource type="Resource" uid="uid://dydn8rsdjxa5k" path="res://resources/sounds/hit.tres" id="6_ntddr"]
|
||||
[ext_resource type="Resource" uid="uid://bk3bsmccptmuo" path="res://resources/sounds/ui_click.tres" id="7_sleq4"]
|
||||
|
||||
[node name="SoundManager" type="Node"]
|
||||
script = ExtResource("1_n6pv8")
|
||||
music = Array[ExtResource("2_vxk68")]([ExtResource("3_f5ali"), ExtResource("4_fn62j")])
|
||||
sfx = Array[ExtResource("2_vxk68")]([ExtResource("5_tids3"), ExtResource("6_ntddr"), ExtResource("7_sleq4")])
|
||||
|
||||
[node name="BackgroundMusicPlayer" type="AudioStreamPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
volume_db = 5.0
|
||||
bus = &"Music"
|
||||
Loading…
Add table
Add a link
Reference in a new issue