From c2210ecd1736e0bc3bad5e834c8200230eb95a52 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 1 Mar 2023 16:06:01 +0100 Subject: [PATCH] Added background music --- .build.yml | 1 + .gitignore | 2 ++ Cargo.lock | 1 + Cargo.toml | 1 + README.md | 8 +++++++- fetch-assets.sh | 12 ++++++++++++ src/main.rs | 13 +++++++++++++ 7 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.build.yml b/.build.yml index 34a3bf5..b9c58b6 100644 --- a/.build.yml +++ b/.build.yml @@ -4,6 +4,7 @@ sources: packages: - mingw-w64-gcc - wget + - ffmpeg - clang - alsa-lib-dev - protoc diff --git a/.gitignore b/.gitignore index bcec0fd..ecb8783 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ assets/exp/ assets/desert assets/fonts/ assets/ui/ +assets/music.wav +assets/music.mp3 local.data diff --git a/Cargo.lock b/Cargo.lock index d3225b9..0330da6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1628,6 +1628,7 @@ dependencies = [ "macroquad", "nanoserde", "quad-rand", + "quad-snd", "quad-storage", ] diff --git a/Cargo.toml b/Cargo.toml index 0491dec..4e4133f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,4 @@ libp2p = { version = "0.51.0", features = [ futures = { version = "0.3.26", optional = true } async-std = { version = "1.12.0", optional = true } quad-rand = { version = "0.2.1", optional = true } +quad-snd = "0.2.7" diff --git a/README.md b/README.md index 7d6d30d..0370ef0 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ with this 2D game - [ ] place block with single click - [ ] destroy block with long click - [ ] Settings menu (i.e for Keybindings) -- [ ] Background music (ambient) +- [x] Background music (ambient) - [x] Add more assets - [x] SketchTown Expansion pack - [x] (MAYBE) [Sketch Desert](https://kenney.nl/assets/sketch-desert) @@ -122,3 +122,9 @@ See below or a detailed list: - [Sektch Desert](https://kenney.nl/assets/sketch-desert) asset pack - [UI Pack: RPG Expansion](https://kenney.nl/assets/ui-pack-rpg-expansion) asset pack - [Kenney Fonts](https://kenney.nl/assets/kenney-fonts) + +The Background music has been obtained from [pixabay](https://pixabay.com/music/solo-piano-raining-ambient-calm-piano-music-loop-111521/). +The song is called *Raining - Ambient Calm Piano Music*, +and has been comosed by *HarumachiMusic*. +According to the [pixabey license](https://pixabay.com/service/license/), +it may be used for personal and commercial use. diff --git a/fetch-assets.sh b/fetch-assets.sh index 5e6e3ab..a04d801 100755 --- a/fetch-assets.sh +++ b/fetch-assets.sh @@ -6,6 +6,8 @@ rm -rf assets/exp rm -rf assets/desert rm -rf assets/fonts rm -rf assets/ui +rm assets/music.mp3 +rm assets/music.wav # enable failsafe set -e @@ -58,3 +60,13 @@ wget https://kenney.nl/content/3-assets/137-kenney-fonts/kenney_fontpackage.zip unzip assets/fonts.zip -d assets/fonts rm assets/fonts.zip echo "✅ Extracting fonts done" + +# fetch music +echo "⏳ Downloading Music" +echo "from https://pixabay.com/music/solo-piano-raining-ambient-calm-piano-music-loop-111521/" +echo "Titled Raining - Ambient Calm Piano Music ( loop ) by HarumachiMusic" +wget https://cdn.pixabay.com/download/audio/2022/05/18/audio_281d895824.mp3?filename=raining-ambient-calm-piano-music-loop-111521.mp3 \ + -O assets/music.mp3 +ffmpeg -i assets/music.mp3 assets/music.wav +rm assets/music.mp3 +echo "✅ Downloaded music" diff --git a/src/main.rs b/src/main.rs index f3d1afe..b0446f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,12 @@ mod game; #[cfg(feature = "multiplayer")] mod p2p; +use quad_snd::{ + Sound, + AudioContext, + PlaySoundParams +}; + use game::{ GameComponent, GameEvent @@ -28,6 +34,13 @@ async fn main() { let mut screen = Screen::default(); + let mut ctx = AudioContext::new(); + let mut sound = Sound::load(&mut ctx, include_bytes!("../assets/music.wav")); + sound.play(&mut ctx, PlaySoundParams{ + looped: true, + volume: 0.2 + }); + loop { clear_background(Color::from_rgba(215, 189, 165, 255)); -- 2.38.5