diff --git a/src/main.rs b/src/main.rs index 473e6e7..ba8f74e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,9 @@ use sound::{Sound, SoundEffect, SoundEffectSamples, SoundSystem}; use specs::prelude::*; use specs_derive::Component; use std::{ + array, cmp::{max, min}, + iter, time::{Duration, Instant}, }; use vga_color as vga; @@ -22,6 +24,7 @@ struct LevelNumber(u32); struct SoundEffects { step_sound: SoundEffectSamples, pickup_sound: SoundEffectSamples, + bad_key_sound: SoundEffectSamples, } #[derive(Component)] @@ -104,7 +107,11 @@ fn player_input(gs: &mut State, ctx: &mut BTerm) { let pickup_sound = sound_effects.pickup_sound.clone(); gs.sound_system.play_sound(pickup_sound); } - _ => {} + _ => { + let sound_effects = gs.ecs.fetch::(); + 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 { ecs: World::new(), // sound_sender: tx, @@ -202,6 +229,7 @@ fn main() -> BError { gs.ecs.insert(SoundEffects { step_sound, pickup_sound, + bad_key_sound, }); gs.ecs.register::();