mirror of
https://github.com/kodzukye/omens-ascent.git
synced 2026-08-10 05:13:10 +00:00
88 lines
2.8 KiB
GDScript
88 lines
2.8 KiB
GDScript
extends Node
|
|
|
|
# Will need to be able to adapt volume as it can be too loud
|
|
const AMBIANCE_VOLUME_DB: float = -18.0
|
|
const SFX_VOLUME_DB: float = -12.0
|
|
|
|
const AMBIANCES: Dictionary = {
|
|
"act1_section1": preload("res://assets/audio/music/a_warriors_path.ogg"),
|
|
"act2_floor1": preload("res://assets/audio/music/the_dungeon.ogg"),
|
|
"boss_arena": preload("res://assets/audio/music/the_red_death.ogg")
|
|
}
|
|
|
|
const JINGLES: Dictionary = {
|
|
"success": preload("res://assets/audio/sfx/Jingles/Success.wav")
|
|
}
|
|
|
|
const SFX: Dictionary = {
|
|
"game_over": preload("res://assets/audio/sfx/Jingles/GameOver.wav"),
|
|
"options_move": preload("res://assets/audio/sfx/Sounds/Move.wav"),
|
|
"jump": preload("res://assets/audio/sfx/Sounds/Jump.wav"),
|
|
"slash_1": preload("res://assets/audio/sfx/Sounds/Slash.wav"),
|
|
"heal": preload("res://assets/audio/sfx/Sounds/HeartBonus.wav"),
|
|
"door_unlock": preload("res://assets/audio/sfx/Sounds/door_unlocking.ogg"),
|
|
}
|
|
|
|
var music_player : AudioStreamPlayer
|
|
var sfx_player : AudioStreamPlayer
|
|
var jingle_player : AudioStreamPlayer
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
music_player = AudioStreamPlayer.new()
|
|
music_player.name = "MusicPlayer"
|
|
music_player.bus = "Ambient"
|
|
music_player.volume_db = AMBIANCE_VOLUME_DB
|
|
add_child(music_player)
|
|
music_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
sfx_player = AudioStreamPlayer.new()
|
|
sfx_player.name = "SfxPlayer"
|
|
sfx_player.bus = "SFX"
|
|
sfx_player.volume_db = SFX_VOLUME_DB
|
|
add_child(sfx_player)
|
|
sfx_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
jingle_player = AudioStreamPlayer.new()
|
|
jingle_player.name = "JinglePlayer"
|
|
jingle_player.bus = "Jingle"
|
|
jingle_player.volume_db = SFX_VOLUME_DB
|
|
add_child(jingle_player)
|
|
jingle_player.process_mode = Node.PROCESS_MODE_ALWAYS
|
|
|
|
music_player.finished.connect(_on_music_finished)
|
|
|
|
func play_ambiance(zone: String) -> void:
|
|
if not AMBIANCES.has(zone):
|
|
return
|
|
if music_player.stream == AMBIANCES[zone] and music_player.playing:
|
|
return
|
|
|
|
var tween: Tween = create_tween()
|
|
tween.tween_property(music_player, "volume_db", -40.0, 0.8)
|
|
tween.tween_callback(func():
|
|
music_player.stream = AMBIANCES[zone]
|
|
music_player.play()
|
|
)
|
|
tween.tween_property(music_player, "volume_db", AMBIANCE_VOLUME_DB, 1.2)
|
|
|
|
func stop_ambiance() -> void:
|
|
var tween: Tween = create_tween()
|
|
tween.tween_property(music_player, "volume_db", -40.0, 1.0)
|
|
tween.tween_callback(music_player.stop)
|
|
|
|
func play_sfx(sfx_name: String) -> void:
|
|
if not SFX.has(sfx_name):
|
|
push_warning("SFX introuvable : " + sfx_name)
|
|
return
|
|
sfx_player.stream = SFX[sfx_name]
|
|
sfx_player.play()
|
|
|
|
func play_jingle(jingle_name) -> void:
|
|
jingle_player.stream = JINGLES[jingle_name]
|
|
jingle_player.play()
|
|
|
|
func _on_music_finished() -> void:
|
|
music_player.play()
|