Move map and sound stuff to resources module
This commit is contained in:
parent
a8500b96d2
commit
6ce6470236
7 changed files with 23 additions and 14 deletions
114
src/resources/sound_effects.rs
Normal file
114
src/resources/sound_effects.rs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
use std::{array, iter, time::Duration};
|
||||
|
||||
use bracket_lib::random::RandomNumberGenerator;
|
||||
|
||||
use crate::resources::sound_system::{
|
||||
Sound, SoundEffect, SoundEffectSamples, SoundSystem, SoundType,
|
||||
};
|
||||
|
||||
pub struct SoundEffects {
|
||||
pub startup: SoundEffectSamples,
|
||||
pub step: SoundEffectSamples,
|
||||
pub pickup: SoundEffectSamples,
|
||||
pub bad_key: SoundEffectSamples,
|
||||
pub blocked: SoundEffectSamples,
|
||||
rng: RandomNumberGenerator,
|
||||
}
|
||||
|
||||
impl SoundEffects {
|
||||
pub fn new(ss: &SoundSystem) -> Self {
|
||||
Self {
|
||||
startup: ss.render_sound_effect(&SoundEffect {
|
||||
sounds: (30..400)
|
||||
.step_by(8)
|
||||
.map(|x| Sound {
|
||||
sound_type: SoundType::Tone(x),
|
||||
duration: Duration::from_millis(24),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
step: ss.render_sound_effect(&SoundEffect {
|
||||
sounds: vec![
|
||||
Sound {
|
||||
sound_type: SoundType::Noise(350, 900),
|
||||
duration: Duration::from_millis(6),
|
||||
},
|
||||
Sound {
|
||||
sound_type: SoundType::Silence,
|
||||
duration: Duration::from_millis(120),
|
||||
},
|
||||
Sound {
|
||||
sound_type: SoundType::Noise(150, 200),
|
||||
duration: Duration::from_millis(6),
|
||||
},
|
||||
],
|
||||
}),
|
||||
pickup: ss.render_sound_effect(&SoundEffect {
|
||||
sounds: vec![
|
||||
Sound {
|
||||
sound_type: SoundType::Noise(350, 900),
|
||||
duration: Duration::from_millis(6),
|
||||
},
|
||||
Sound {
|
||||
sound_type: SoundType::Silence,
|
||||
duration: Duration::from_millis(120),
|
||||
},
|
||||
Sound {
|
||||
sound_type: SoundType::Noise(1000, 2000),
|
||||
duration: Duration::from_millis(20),
|
||||
},
|
||||
],
|
||||
}),
|
||||
bad_key: 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(),
|
||||
}),
|
||||
blocked: ss.render_sound_effect(&SoundEffect {
|
||||
sounds: (30..=60)
|
||||
.rev()
|
||||
.step_by(6)
|
||||
.map(|x| Sound {
|
||||
sound_type: SoundType::Tone(x),
|
||||
duration: Duration::from_millis(18),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
rng: RandomNumberGenerator::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_new_static_effect(&mut self, ss: &SoundSystem) -> SoundEffectSamples {
|
||||
ss.render_sound_effect(&SoundEffect {
|
||||
sounds: (1..=33)
|
||||
.map(|_| {
|
||||
if self.rng.roll_dice(1, 2) > 1 {
|
||||
Sound {
|
||||
sound_type: SoundType::Noise(3000, 7000),
|
||||
duration: Duration::from_millis(self.rng.range(1, 15)),
|
||||
}
|
||||
} else {
|
||||
Sound {
|
||||
sound_type: SoundType::Silence,
|
||||
duration: Duration::from_millis(self.rng.range(0, 30)),
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue