Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-139: Add Music #140

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
1 change: 1 addition & 0 deletions #Scenes/SceneScripts/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,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 Down
1 change: 1 addition & 0 deletions #Scenes/SceneScripts/ShopScene.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.SHOP)
SaveManager.execute_save()
20 changes: 20 additions & 0 deletions #Scenes/SceneScripts/TestingScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,25 @@ 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 number_of_floors: float = MapManager.get_floors()

# Offset by 1 since it's reading from an array
var current_player_floor: float = PlayerManager.player_position.y + 1

var percentage_complete: float = (current_player_floor / number_of_floors) * 100
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
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
else:
music_track = GlobalEnums.MusicTrack.BOSS

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=0
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=0
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=0
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=0
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=0
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=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
16 changes: 16 additions & 0 deletions Global/Global_Enums.gd
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,19 @@ enum PossibleEnemies {
o_beehive,
the_berts,
}

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

# Enums to each SFX
enum SoundEffect {
UUUUU
}
73 changes: 73 additions & 0 deletions Managers/AudioManager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 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
}

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

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

var music_stream: AudioStreamPlayer2D = AudioStreamPlayer2D.new()
var sfx_stream: AudioStreamPlayer2D = AudioStreamPlayer2D.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]
3 changes: 3 additions & 0 deletions Managers/MapManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,6 @@ 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 get_floors() -> int:
return map_width_array.size()
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"

[debug]

Expand Down
Loading