-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from Eraden/audio
Initial audio
- Loading branch information
Showing
13 changed files
with
159 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use ggez::audio::{AudioContext, SoundSource}; | ||
use ggez::context::Has; | ||
use ggez::{audio, Context, GameResult}; | ||
|
||
/// Audio controller responsible for managing which sound should be played now | ||
pub struct AudioState { | ||
/// Main theme played most of the time and interrupted by machines sounds | ||
main: audio::Source, | ||
} | ||
|
||
impl AudioState { | ||
pub fn new(ctx: &impl Has<AudioContext>) -> GameResult<AudioState> { | ||
let data = audio::SoundData::from_bytes(include_bytes!("../../../assets/Red_Planet.mp3")); | ||
let sound = audio::Source::from_data(ctx, data)?; | ||
let s = AudioState { main: sound }; | ||
Ok(s) | ||
} | ||
|
||
/// Plays the sound multiple times | ||
pub fn play_main_theme(&mut self, ctx: &mut Context) { | ||
self.main.play_detached(ctx).ok(); | ||
} | ||
|
||
/// Plays the sound multiple times | ||
pub fn pause_main_theme(&mut self, _ctx: &mut Context) { | ||
self.main.pause(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.