2023-07-20 02:41:17 +10:00
|
|
|
use agb::{
|
|
|
|
include_wav,
|
|
|
|
sound::mixer::{Mixer, SoundChannel},
|
|
|
|
};
|
2023-08-02 06:41:33 +10:00
|
|
|
use agb_tracker::{include_xm, Track, Tracker};
|
|
|
|
|
2023-08-03 01:48:41 +10:00
|
|
|
const MUSIC: Track = include_xm!("sfx/gwilym-theme2.xm");
|
2023-07-20 02:41:17 +10:00
|
|
|
|
|
|
|
const BAD_SELECTION: &[u8] = include_wav!("sfx/bad.wav");
|
|
|
|
const SELECT: &[u8] = include_wav!("sfx/select.wav");
|
|
|
|
const PLACE: &[u8] = include_wav!("sfx/place.wav");
|
|
|
|
|
|
|
|
const SLIME_DEATH: &[u8] = include_wav!("sfx/slime_death.wav");
|
|
|
|
const SWORD_PICKUP: &[u8] = include_wav!("sfx/sword_pickup.wav");
|
|
|
|
const WALL_HIT: &[u8] = include_wav!("sfx/wall_hit.wav");
|
|
|
|
const DOOR_OPEN: &[u8] = include_wav!("sfx/door_open.wav");
|
|
|
|
|
|
|
|
const SWICTH_TOGGLES: &[&[u8]] = &[include_wav!("sfx/switch_toggle1.wav")];
|
|
|
|
|
|
|
|
pub struct Sfx<'a> {
|
|
|
|
mixer: &'a mut Mixer<'a>,
|
2023-08-02 06:41:33 +10:00
|
|
|
tracker: Tracker,
|
2023-07-20 02:41:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Sfx<'a> {
|
|
|
|
pub fn new(mixer: &'a mut Mixer<'a>) -> Self {
|
|
|
|
mixer.enable();
|
|
|
|
|
2023-08-02 06:41:33 +10:00
|
|
|
let tracker = Tracker::new(&MUSIC);
|
|
|
|
|
|
|
|
Self { mixer, tracker }
|
2023-07-20 02:41:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn frame(&mut self) {
|
2023-08-02 06:41:33 +10:00
|
|
|
self.tracker.step(self.mixer);
|
2023-07-20 02:41:17 +10:00
|
|
|
self.mixer.frame();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn bad_selection(&mut self) {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(BAD_SELECTION));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn select(&mut self) {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(SELECT));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn place(&mut self) {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(PLACE));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn play_sound_effect(&mut self, effect: Option<SoundEffect>) {
|
|
|
|
if let Some(effect) = effect {
|
|
|
|
match effect {
|
2023-07-26 05:39:14 +10:00
|
|
|
SoundEffect::WallHit => {
|
2023-07-20 02:41:17 +10:00
|
|
|
self.mixer.play_sound(SoundChannel::new(WALL_HIT));
|
|
|
|
}
|
|
|
|
SoundEffect::SlimeDie => {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(SLIME_DEATH));
|
|
|
|
}
|
|
|
|
SoundEffect::HeroDie => {}
|
|
|
|
SoundEffect::SquidDie => {}
|
|
|
|
SoundEffect::SwordPickup => {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(SWORD_PICKUP));
|
|
|
|
}
|
2023-07-26 05:39:14 +10:00
|
|
|
SoundEffect::SwordKill => {}
|
2023-07-20 02:41:17 +10:00
|
|
|
SoundEffect::KeyPickup => {}
|
|
|
|
SoundEffect::DoorOpen => {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(DOOR_OPEN));
|
|
|
|
}
|
|
|
|
SoundEffect::SwitchToggle => {
|
|
|
|
self.mixer.play_sound(SoundChannel::new(SWICTH_TOGGLES[0]));
|
|
|
|
}
|
|
|
|
SoundEffect::KeyDrop => {}
|
|
|
|
SoundEffect::SwordDrop => {}
|
|
|
|
SoundEffect::SwitchedDoorToggle => {}
|
|
|
|
SoundEffect::SpikesToggle => {}
|
2023-08-30 06:44:28 +10:00
|
|
|
SoundEffect::TeleportEffect => {}
|
2023-07-20 02:41:17 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
|
|
|
|
pub enum SoundEffect {
|
|
|
|
SlimeDie,
|
|
|
|
HeroDie,
|
|
|
|
SquidDie,
|
|
|
|
SwordPickup,
|
|
|
|
SwordKill,
|
|
|
|
KeyPickup,
|
|
|
|
DoorOpen,
|
|
|
|
SwitchToggle,
|
|
|
|
KeyDrop,
|
|
|
|
SwordDrop,
|
|
|
|
SwitchedDoorToggle,
|
|
|
|
SpikesToggle,
|
|
|
|
WallHit,
|
2023-08-30 06:44:28 +10:00
|
|
|
TeleportEffect,
|
2023-07-20 02:41:17 +10:00
|
|
|
}
|