From 5284b33808a30f9c9adfd95ca3a2b2017c2de963 Mon Sep 17 00:00:00 2001 From: Alex Page Date: Tue, 25 Jan 2022 17:56:18 -0500 Subject: [PATCH] Add electric static sound effect --- src/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 369315c..8bb2d00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,8 +77,25 @@ fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World, sound_system: &m || destination_y < 0 || (destination_y as usize) >= MAP_HEIGHT { - let blocked_sound = sound_effects.blocked_sound.clone(); - sound_system.play_sound(blocked_sound); + let mut rng = RandomNumberGenerator::new(); + let static_sound = sound_system.render_sound_effect(&SoundEffect { + sounds: (1..=33) + .map(|_| { + if rng.roll_dice(1, 2) > 1 { + Sound { + sound_type: SoundType::Noise(3000, 7000), + duration: Duration::from_millis(rng.range(1, 15)), + } + } else { + Sound { + sound_type: SoundType::Silence, + duration: Duration::from_millis(rng.range(0, 30)), + } + } + }) + .collect(), + }); + sound_system.play_sound(static_sound); player.last_moved = now; continue; }