Skip to content

Commit

Permalink
Background Music
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Jan 3, 2024
1 parent 3849466 commit 3e0ac2d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
Binary file added src/Music/BackgroundMusic.ogg
Binary file not shown.
6 changes: 6 additions & 0 deletions src/Shared.zig
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ pub const Shared = struct {
raylib.updateMusicStream(s.?);
}
}
pub inline fn SetVolume(music: AssetManager.Musics, volume: f32) void {
const s = Get(music);
if (s != null) {
raylib.setMusicVolume(s.?, volume);
}
}
};

pub const Settings = struct {
Expand Down
2 changes: 2 additions & 0 deletions src/ViewModels/AsteroidsViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub const AsteroidsViewModel = Shared.View.ViewModel.Create(
pub inline fn init() void {
starScape = Starscape.init(screenSize);

Shared.Music.SetVolume(.BackgroundMusic, 0.35);

const settings = Shared.Settings.GetSettings();
if (settings.NoDamage != null) {
takeDamage = !settings.NoDamage.?;
Expand Down
2 changes: 2 additions & 0 deletions src/Views/AsteroidsView.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fn DrawFunction() Shared.View.Views {
}

fn DrawWithCamera() Shared.View.Views {
Shared.Music.Play(.BackgroundMusic);

const camera = Shared.Camera.initScaledTargetCamera(
vm.screenSize,
3.5,
Expand Down

0 comments on commit 3e0ac2d

Please sign in to comment.