Add bad key sound

This commit is contained in:
Alex Page 2022-01-24 22:11:30 -05:00
parent 7cd29b5ffa
commit 02270fb4b0

View file

@ -5,7 +5,9 @@ use sound::{Sound, SoundEffect, SoundEffectSamples, SoundSystem};
use specs::prelude::*; use specs::prelude::*;
use specs_derive::Component; use specs_derive::Component;
use std::{ use std::{
array,
cmp::{max, min}, cmp::{max, min},
iter,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use vga_color as vga; use vga_color as vga;
@ -22,6 +24,7 @@ struct LevelNumber(u32);
struct SoundEffects { struct SoundEffects {
step_sound: SoundEffectSamples, step_sound: SoundEffectSamples,
pickup_sound: SoundEffectSamples, pickup_sound: SoundEffectSamples,
bad_key_sound: SoundEffectSamples,
} }
#[derive(Component)] #[derive(Component)]
@ -104,7 +107,11 @@ fn player_input(gs: &mut State, ctx: &mut BTerm) {
let pickup_sound = sound_effects.pickup_sound.clone(); let pickup_sound = sound_effects.pickup_sound.clone();
gs.sound_system.play_sound(pickup_sound); gs.sound_system.play_sound(pickup_sound);
} }
_ => {} _ => {
let sound_effects = gs.ecs.fetch::<SoundEffects>();
let bad_key_sound = sound_effects.bad_key_sound.clone();
gs.sound_system.play_sound(bad_key_sound);
}
}, },
} }
} }
@ -191,6 +198,26 @@ fn main() -> BError {
], ],
}); });
let bad_key_sound = ss.render_sound_effect(&SoundEffect {
sounds: iter::once(Sound {
sound_type: SoundType::Tone(400),
duration: Duration::from_millis(20),
})
.chain((0..4).flat_map(|_| {
array::IntoIter::new([
Sound {
sound_type: SoundType::Tone(100),
duration: Duration::from_millis(15),
},
Sound {
sound_type: SoundType::Silence,
duration: Duration::from_millis(15),
},
])
}))
.collect(),
});
let mut gs = State { let mut gs = State {
ecs: World::new(), ecs: World::new(),
// sound_sender: tx, // sound_sender: tx,
@ -202,6 +229,7 @@ fn main() -> BError {
gs.ecs.insert(SoundEffects { gs.ecs.insert(SoundEffects {
step_sound, step_sound,
pickup_sound, pickup_sound,
bad_key_sound,
}); });
gs.ecs.register::<Position>(); gs.ecs.register::<Position>();