Skip to content

Commit

Permalink
Issue-139: Add Music (#140)
Browse files Browse the repository at this point in the history
* Issue-139: Add all music tracks, Implemented AudioManager, Add playing music when starting a new game

* Issue-139: Loop music tracks, Add cicadas track to Main Menu
  • Loading branch information
Tysterman74 authored Dec 27, 2024
1 parent ac4807f commit fe436c2
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 0 deletions.
1 change: 1 addition & 0 deletions #Scenes/SceneScripts/HealScene.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extends Control

func _ready() -> void:
AudioManager.start_music(GlobalEnums.MusicTrack.HEAL)
SaveManager.execute_save()
5 changes: 5 additions & 0 deletions #Scenes/SceneScripts/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var continue_button: TextureButton

#on opening the main menu we grab the focus of the start button
func _ready() -> void:
AudioManager.start_music(GlobalEnums.MusicTrack.MAIN_MENU)
$"Menu buttons/Continue".grab_focus()
$"game version".text = ProjectSettings.get_setting("application/config/version")
for child in get_node("Menu buttons").get_children():
Expand All @@ -22,11 +23,13 @@ func _on_start_pressed() -> void:
if SaveManager.has_saved_data():
start_new_game_dialog.show()
else:
AudioManager.stop_music()
_init_managers()
SceneManager.goto_scene("res://#Scenes/MapUI.tscn")

func _on_continue_pressed() -> void:
if SaveManager.has_saved_data():
AudioManager.stop_music()
PlayerManager.load_player()
MapManager.load_map_data()
XpManager.load_data()
Expand All @@ -40,6 +43,7 @@ func _on_button_hovered(button: TextureButton) -> void:

## Scene to be loaded when option button is pressed
func _on_options_pressed() -> void:
AudioManager.play_sfx(GlobalEnums.SoundEffect.UUUUU)
SceneManager.goto_scene("res://#Scenes/OptionsMenu.tscn")


Expand All @@ -54,6 +58,7 @@ func _on_credits_pressed() -> void:

func _on_start_new_game_dialog_confirmed() -> void:
SaveManager.clear_data()
AudioManager.stop_music()
_init_managers()
SceneManager.goto_scene("res://#Scenes/MapUI.tscn")

Expand Down
1 change: 1 addition & 0 deletions #Scenes/SceneScripts/ShopScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Control
class_name ShopScene

func _ready() -> void:
AudioManager.start_music(GlobalEnums.MusicTrack.SHOP)

# This code has to happen after the map has done '.on_event_started' [br]
# so I just put a .1 delay on it
Expand Down
15 changes: 15 additions & 0 deletions #Scenes/SceneScripts/TestingScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,20 @@ extends Node2D
## Now that the main scene is the main menu and we load the testing scene from there, we init to properly init the game state

func _ready() -> void:
_play_music()
SaveManager.execute_save()
PhaseManager.initialize_game()

func _play_music() -> void:
var percentage_complete: float = MapManager.get_map_percent_with_player_position()
var music_track: GlobalEnums.MusicTrack
if MapManager.is_on_last_floor():
music_track = GlobalEnums.MusicTrack.BOSS
elif percentage_complete <= 33:
music_track = GlobalEnums.MusicTrack.AREA_ONE
elif percentage_complete > 33 and percentage_complete <= 66:
music_track = GlobalEnums.MusicTrack.AREA_TWO
elif percentage_complete > 66 and percentage_complete <= 99:
music_track = GlobalEnums.MusicTrack.AREA_THREE

AudioManager.start_music(music_track)
1 change: 1 addition & 0 deletions #Scenes/SceneScripts/TestingScene_UIcontrol.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ extends Control


func _on_back_to_main_menu_pressed() -> void:
AudioManager.stop_music()
SceneManager.goto_scene("res://#Scenes/MainMenu.tscn")
Binary file added Audio/Battle/area_1.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/Battle/area_1.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://bcul2j5636jou"
path="res://.godot/imported/area_1.wav-2c34baa1e3757ba46478140199d2135e.sample"

[deps]

source_file="res://Audio/Battle/area_1.wav"
dest_files=["res://.godot/imported/area_1.wav-2c34baa1e3757ba46478140199d2135e.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added Audio/Battle/area_2.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/Battle/area_2.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://c1l85a2sb0uvx"
path="res://.godot/imported/area_2.wav-1fe080959541db71ffe9c331b81c4fb5.sample"

[deps]

source_file="res://Audio/Battle/area_2.wav"
dest_files=["res://.godot/imported/area_2.wav-1fe080959541db71ffe9c331b81c4fb5.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added Audio/Battle/area_3.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/Battle/area_3.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://c87sumxo08tbt"
path="res://.godot/imported/area_3.wav-e75c187215113b3d3dba7cc6f9d09a31.sample"

[deps]

source_file="res://Audio/Battle/area_3.wav"
dest_files=["res://.godot/imported/area_3.wav-e75c187215113b3d3dba7cc6f9d09a31.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added Audio/Battle/boss_1.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/Battle/boss_1.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dv22f2psd5s2u"
path="res://.godot/imported/boss_1.wav-0297eb94cdd4630efa5f828b2e37dc8f.sample"

[deps]

source_file="res://Audio/Battle/boss_1.wav"
dest_files=["res://.godot/imported/boss_1.wav-0297eb94cdd4630efa5f828b2e37dc8f.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added Audio/MainMenu/cicadas.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/MainMenu/cicadas.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dn4vvohka34oa"
path="res://.godot/imported/cicadas.wav-dcbeb09c6e6173bc4f40cabe17efe450.sample"

[deps]

source_file="res://Audio/MainMenu/cicadas.wav"
dest_files=["res://.godot/imported/cicadas.wav-dcbeb09c6e6173bc4f40cabe17efe450.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added Audio/World/heal.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/World/heal.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dg6gyqm1ejosu"
path="res://.godot/imported/heal.wav-5ab6d90a27f406b6b2d2e28cb6291aa4.sample"

[deps]

source_file="res://Audio/World/heal.wav"
dest_files=["res://.godot/imported/heal.wav-5ab6d90a27f406b6b2d2e28cb6291aa4.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added Audio/World/shop.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions Audio/World/shop.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://cpbi46kxjtqm7"
path="res://.godot/imported/shop.wav-cb470f972d3892abc362f53b8b54009b.sample"

[deps]

source_file="res://Audio/World/shop.wav"
dest_files=["res://.godot/imported/shop.wav-cb470f972d3892abc362f53b8b54009b.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=2
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
13 changes: 13 additions & 0 deletions Dialog/EventDialogueWindow.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var dialogue_line: DialogueLine:


func _ready() -> void:
_play_music()
SaveManager.execute_save()
balloon.hide()
Engine.get_singleton("DialogueManager").mutated.connect(_on_mutated)
Expand Down Expand Up @@ -177,3 +178,15 @@ func add_flavor_text(flavor_text: String, flavor_number: int) -> void:

func _on_responses_menu_response_selected(response: DialogueResponse) -> void:
next(response.next_id)

func _play_music() -> void:
var percentage_complete: float = MapManager.get_map_percent_with_player_position()
var music_track: GlobalEnums.MusicTrack
if percentage_complete <= 33:
music_track = GlobalEnums.MusicTrack.AREA_ONE
elif percentage_complete > 33 and percentage_complete <= 66:
music_track = GlobalEnums.MusicTrack.AREA_TWO
elif percentage_complete > 66 and percentage_complete <= 99:
music_track = GlobalEnums.MusicTrack.AREA_THREE

AudioManager.start_music(music_track)
17 changes: 17 additions & 0 deletions Global/Global_Enums.gd
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ enum PossibleEnemies {
the_berts,
}

# Enums to each music track
enum MusicTrack {
AREA_ONE,
AREA_TWO,
AREA_THREE,
BOSS,
HEAL,
SHOP,
MAIN_MENU,
NO_TRACK
}

# Enums to each SFX
enum SoundEffect {
UUUUU
}

enum CardType {
ATTACK,
SKILL,
Expand Down
75 changes: 75 additions & 0 deletions Managers/AudioManager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
extends Node


# Music
var battle_area_1: AudioStream = preload("res://Audio/Battle/area_1.wav")
var battle_area_2: AudioStream = preload("res://Audio/Battle/area_2.wav")
var battle_area_3: AudioStream = preload("res://Audio/Battle/area_3.wav")
var boss: AudioStream = preload("res://Audio/Battle/boss_1.wav")
var heal_event: AudioStream = preload("res://Audio/World/heal.wav")
var shop_event: AudioStream = preload("res://Audio/World/shop.wav")
var main_menu: AudioStream = preload("res://Audio/MainMenu/cicadas.wav")

var music_dictionary: Dictionary = {
GlobalEnums.MusicTrack.AREA_ONE: battle_area_1,
GlobalEnums.MusicTrack.AREA_TWO: battle_area_2,
GlobalEnums.MusicTrack.AREA_THREE: battle_area_3,
GlobalEnums.MusicTrack.BOSS: boss,
GlobalEnums.MusicTrack.HEAL: heal_event,
GlobalEnums.MusicTrack.SHOP: shop_event,
GlobalEnums.MusicTrack.MAIN_MENU: main_menu
}

# SFX
var uuuuu: AudioStream = preload("res://Audio/fauna_uuu_test.mp3")

var sfx_dictionary: Dictionary = {
GlobalEnums.SoundEffect.UUUUU: uuuuu
}

var music_stream: AudioStreamPlayer = AudioStreamPlayer.new()
var sfx_stream: AudioStreamPlayer = AudioStreamPlayer.new()

var current_song: GlobalEnums.MusicTrack = GlobalEnums.MusicTrack.NO_TRACK

func _ready() -> void:
add_child(music_stream)
add_child(sfx_stream)

func start_music(song: GlobalEnums.MusicTrack) -> void:
if current_song == song or song == GlobalEnums.MusicTrack.NO_TRACK:
return

if music_stream.playing and current_song != song:
var volume_tween: Tween = create_tween()
volume_tween.tween_property(music_stream, "volume_db", -100, 1)
volume_tween.tween_callback(_on_volume_fade_finished.bind(song))
else:
_on_volume_fade_finished(song)

func stop_music() -> void:
var volume_tween: Tween = create_tween()
volume_tween.tween_property(music_stream, "volume_db", -100, 0.25)
volume_tween.tween_callback(_on_volume_fade_stop)

func _on_volume_fade_stop() -> void:
current_song = GlobalEnums.MusicTrack.NO_TRACK
music_stream.volume_db = 0
music_stream.stop()

func _on_volume_fade_finished(song: GlobalEnums.MusicTrack) -> void:
music_stream.stream = _get_music_track(song)
music_stream.volume_db = 0
music_stream.play()
current_song = song

func _get_music_track(song: GlobalEnums.MusicTrack) -> AudioStream:
return music_dictionary[song]

func play_sfx(sfx: GlobalEnums.SoundEffect) -> void:
sfx_stream.stream = _get_sound_effect(sfx)
sfx_stream.volume_db = 0
sfx_stream.play()

func _get_sound_effect(sfx: GlobalEnums.SoundEffect) -> AudioStream:
return sfx_dictionary[sfx]
8 changes: 8 additions & 0 deletions Managers/MapManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,11 @@ func get_map_percent_with_player_position() -> float:
var number_of_floors: int = map_width_array.size()
var player_y_floor: int = player_position.y
return (player_y_floor as float / number_of_floors as float) * 100

func is_on_last_floor() -> bool:
var number_of_floors: int = map_width_array.size()

# Add one since we want to compare the number of floors and player position is zero-index based
var player_position_y: int = PlayerManager.player_position.y + 1

return number_of_floors == player_position_y
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MapManager="*res://Managers/MapManager.gd"
InventoryManager="*res://Managers/InventoryManager.gd"
DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd"
XpManager="*res://Managers/XpManager.gd"
AudioManager="*res://Managers/AudioManager.gd"
ShopManager="*res://Shop/ShopManager.tscn"

[debug]
Expand Down

0 comments on commit fe436c2

Please sign in to comment.