Skip to content

Commit

Permalink
fix: Increase BGM volume
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxTube committed Jul 29, 2024
1 parent c02ab83 commit 50ea628
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Binary file modified assets/audio/ending_bgm.ogg
Binary file not shown.
20 changes: 14 additions & 6 deletions src/audio/bgm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use crate::{npc::narrator::TriggeredNarratorDialogue, GameAssets, GameState};

use super::GameAudio;

const BGM_VOLUME: f64 = 0.08;
const MAIN_BGM_VOLUME: f64 = 0.15;
const ENDING_BGM_VOLUME: f64 = 0.2;
const BGM_FADE_OUT: f32 = 4.0;

#[derive(Component)]
struct Bgm {
handle: Handle<AudioInstance>,
volume: f64,
}

#[derive(Component, Deref, DerefMut)]
Expand All @@ -30,23 +32,26 @@ fn spawn_main_bgm(
audio: Res<Audio>,
game_audio: Res<GameAudio>,
) {
let volume = game_audio.main_volume * BGM_VOLUME;
let volume = game_audio.main_volume * MAIN_BGM_VOLUME;
let handle = audio
.play(assets.main_bgm.clone())
.with_volume(volume)
.looped()
.handle();
commands.spawn(Bgm { handle });
commands.spawn(Bgm {
handle,
volume: MAIN_BGM_VOLUME,
});
}

fn update_bgm_volumes(
game_audio: Res<GameAudio>,
mut audio_instances: ResMut<Assets<AudioInstance>>,
q_bgms: Query<&Bgm>,
) {
let volume = game_audio.main_volume * BGM_VOLUME;
for bgm in &q_bgms {
if let Some(instance) = audio_instances.get_mut(bgm.handle.id()) {
let volume = game_audio.main_volume * bgm.volume;
instance.set_volume(volume, AudioTween::default());
}
}
Expand All @@ -71,12 +76,15 @@ fn spawn_ending_bgm(
audio: Res<Audio>,
game_audio: Res<GameAudio>,
) {
let volume = game_audio.main_volume * BGM_VOLUME;
let volume = game_audio.main_volume * MAIN_BGM_VOLUME;
let handle = audio
.play(assets.ending_bgm.clone())
.with_volume(volume)
.handle();
commands.spawn(Bgm { handle });
commands.spawn(Bgm {
handle,
volume: ENDING_BGM_VOLUME,
});
}

pub struct BgmPlugin;
Expand Down

0 comments on commit 50ea628

Please sign in to comment.