2020-09-28 21:18:07 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
onready var _current_music_player = $MusicPlayer1
|
|
|
|
onready var _next_music_player= $MusicPlayer2
|
|
|
|
|
|
|
|
var _SILENT = -40.0
|
|
|
|
var _DESIRED_VOLUME = -15.0
|
|
|
|
var _DESIRED_SFX_VOLUME = -10.0
|
|
|
|
|
|
|
|
var _DESIRED_PAUSE_VOLUME = -25.0
|
|
|
|
|
|
|
|
enum Music{
|
|
|
|
Intro,
|
2020-10-20 13:51:17 +00:00
|
|
|
Abandon,
|
|
|
|
PreGame
|
2020-09-28 21:18:07 +00:00
|
|
|
}
|
|
|
|
var _music_files := {
|
|
|
|
Music.Intro: load("res://assets/Audio/Dungeon - Altus Stratum.ogg"),
|
2020-10-20 13:51:17 +00:00
|
|
|
Music.Abandon: load("res://assets/Audio/Dungeon - Abandoned One.ogg"),
|
|
|
|
Music.PreGame: load("res://assets/Audio/Scene - Lucid Night.ogg")
|
2020-09-28 21:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum Sfx{
|
|
|
|
COIN_COLLECTION,
|
|
|
|
PLAYER_JUMP,
|
|
|
|
PLAYER_LAND,
|
|
|
|
PLAYER_DASH,
|
|
|
|
PLAYER_ATTACK,
|
|
|
|
PLAYER_DIE,
|
|
|
|
UI_MOVE,
|
2020-11-06 21:05:55 +00:00
|
|
|
UI_SELECT,
|
|
|
|
SPRING,
|
2020-11-11 03:58:40 +00:00
|
|
|
SPIKE_TRAP,
|
|
|
|
VASE_BREAK
|
2020-09-28 21:18:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _sfx_files := {
|
|
|
|
Sfx.COIN_COLLECTION : load("res://assets/Audio/SFX/coin.wav"),
|
2020-10-21 02:33:58 +00:00
|
|
|
Sfx.PLAYER_JUMP : load("res://assets/Audio/SFX/player_jump.wav"),
|
2020-11-01 03:16:29 +00:00
|
|
|
Sfx.PLAYER_LAND : load("res://assets/Audio/SFX/player_land.wav"),
|
|
|
|
Sfx.PLAYER_DASH : load("res://assets/Audio/SFX/player_dash.wav"),
|
2020-09-28 21:18:07 +00:00
|
|
|
Sfx.PLAYER_ATTACK : load("res://assets/Audio/SFX/player_attack.wav"),
|
2020-11-01 03:16:29 +00:00
|
|
|
Sfx.PLAYER_DIE : load("res://assets/Audio/SFX/player_die.wav"),
|
2020-11-06 21:05:55 +00:00
|
|
|
Sfx.SPRING : load("res://assets/Audio/SFX/spring.wav"),
|
|
|
|
Sfx.SPIKE_TRAP : load("res://assets/Audio/SFX/spike_trap.wav"),
|
2020-11-11 03:58:40 +00:00
|
|
|
Sfx.VASE_BREAK : load("res://assets/Audio/SFX/vase_break.wav"),
|
2020-09-28 21:18:07 +00:00
|
|
|
Sfx.UI_MOVE : load("res://assets/Audio/UI_Sounds/menu_move_sound.wav"),
|
|
|
|
Sfx.UI_SELECT : '',
|
|
|
|
}
|
|
|
|
|
|
|
|
var _current_music = null
|
|
|
|
var _next_music = null
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
_current_music_player.volume_db = _SILENT
|
|
|
|
_next_music_player.volume_db = _SILENT
|
|
|
|
var children = $SfxPlayers.get_children()
|
|
|
|
for child in children:
|
|
|
|
var player:AudioStreamPlayer = child
|
|
|
|
player.volume_db = _DESIRED_SFX_VOLUME
|
|
|
|
|
|
|
|
func play_music(music:int, transition_time:float = .5) -> void:
|
|
|
|
_transition_to(music, transition_time)
|
|
|
|
pass
|
|
|
|
|
|
|
|
func set_volume(duration:float=.2, volume:float = _DESIRED_PAUSE_VOLUME):
|
|
|
|
_current_music_player.get_node("Tween").stop_all()
|
|
|
|
_next_music_player.get_node("Tween").stop_all()
|
|
|
|
_current_music_player.get_node("Tween").interpolate_property(_current_music_player, 'volume_db', _current_music_player.volume_db, volume, duration)
|
|
|
|
_current_music_player.get_node("Tween").start()
|
|
|
|
|
|
|
|
func play_sfx(sfx:int, priority:int=0):
|
|
|
|
var sfx_player = _get_available_sfx_player()
|
|
|
|
if sfx_player != null:
|
|
|
|
sfx_player.stream = _sfx_files[sfx]
|
|
|
|
sfx_player.play()
|
|
|
|
pass
|
|
|
|
|
|
|
|
func _transition_to(music:int, duration:float):
|
|
|
|
if _current_music == null:
|
|
|
|
_play_first_music(music, duration)
|
|
|
|
return
|
|
|
|
_next_music = music
|
|
|
|
_next_music_player.stream = _music_files[music]
|
|
|
|
_next_music_player.play()
|
|
|
|
_current_music_player.get_node("Tween").stop_all()
|
|
|
|
_next_music_player.get_node("Tween").stop_all()
|
|
|
|
_current_music_player.get_node("Tween").interpolate_property(_current_music_player, 'volume_db', _current_music_player.volume_db, _SILENT, duration)
|
|
|
|
_next_music_player.get_node("Tween").interpolate_property(_next_music_player, 'volume_db', _next_music_player.volume_db, _DESIRED_VOLUME, duration)
|
|
|
|
_current_music_player.get_node("Tween").start()
|
|
|
|
_next_music_player.get_node("Tween").start()
|
|
|
|
|
|
|
|
func _play_first_music(music:int, duration:float):
|
|
|
|
_current_music = music
|
|
|
|
_current_music_player.stream = _music_files[music]
|
|
|
|
_current_music_player.play()
|
|
|
|
_current_music_player.get_node("Tween").interpolate_property(_current_music_player, 'volume_db', _current_music_player.volume_db, _DESIRED_VOLUME, duration)
|
|
|
|
_current_music_player.get_node("Tween").start()
|
|
|
|
|
|
|
|
|
|
|
|
func _get_available_sfx_player()->AudioStreamPlayer:
|
|
|
|
var children = $SfxPlayers.get_children()
|
|
|
|
for child in children:
|
|
|
|
var player:AudioStreamPlayer = child
|
|
|
|
if not player.playing: return player
|
|
|
|
return null
|
|
|
|
|
|
|
|
func _on_Tween_completed(object: Object, key: NodePath) -> void:
|
|
|
|
if object.volume_db == _DESIRED_VOLUME and _next_music != null:
|
|
|
|
var tmp = _current_music_player
|
|
|
|
_current_music_player = _next_music_player
|
|
|
|
_next_music_player = tmp
|
|
|
|
_next_music_player.stop()
|
|
|
|
_current_music = _next_music
|
|
|
|
_next_music = null
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|