From fc7d47a262c3885733147c5710f13e022e26d10d Mon Sep 17 00:00:00 2001 From: Alula Date: Mon, 21 Sep 2020 16:15:14 +0200 Subject: [PATCH] minor tweaks --- src/npc/mimiga_village.rs | 12 +++++++----- src/scene/game_scene.rs | 2 ++ src/sound/mod.rs | 2 +- src/sound/pixtone.rs | 12 ++++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/npc/mimiga_village.rs b/src/npc/mimiga_village.rs index dad34e1..6031f73 100644 --- a/src/npc/mimiga_village.rs +++ b/src/npc/mimiga_village.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use num_traits::clamp; use crate::common::Direction; @@ -16,11 +18,11 @@ impl NPC { } if self.action_num == 1 { - if self.target_y < self.y { - self.vel_y -= 8; - } else if self.target_y > self.y { - self.vel_y += 8; - } + self.vel_y += match self.target_y.cmp(&self.y) { + Ordering::Less => { -8 } + Ordering::Equal => { 0 } + Ordering::Greater => { 8 } + }; self.vel_y = clamp(self.vel_y, -0x100, 0x100); } diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index 2e88dfe..f66beea 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -754,11 +754,13 @@ impl Scene for GameScene { } if state.key_trigger.weapon_next() { + state.sound_manager.play_sfx(4); self.inventory.next_weapon(); self.weapon_x_pos = 32; } if state.key_trigger.weapon_prev() { + state.sound_manager.play_sfx(4); self.inventory.prev_weapon(); self.weapon_x_pos = 0; } diff --git a/src/sound/mod.rs b/src/sound/mod.rs index 42f11b4..19e4200 100644 --- a/src/sound/mod.rs +++ b/src/sound/mod.rs @@ -293,6 +293,6 @@ fn run(rx: Receiver, bank: SoundBank, stream.play()?; loop { - std::thread::sleep(Duration::from_millis(1)); + std::thread::sleep(Duration::from_millis(10)); } } diff --git a/src/sound/pixtone.rs b/src/sound/pixtone.rs index e479502..cb36d9e 100644 --- a/src/sound/pixtone.rs +++ b/src/sound/pixtone.rs @@ -277,13 +277,13 @@ impl PixTonePlayback { break; } else { let pos = state.1 as usize; - //let s1 = (sample[pos] as f32) / 32768.0; - //let s2 = (sample[clamp(pos + 1, 0, sample.len() - 1)] as f32) / 32768.0; - //let s3 = (sample[clamp(pos + 2, 0, sample.len() - 1)] as f32) / 32768.0; - //let s4 = (sample[pos.saturating_sub(1)] as f32) / 32768.0; + let s1 = (sample[pos] as f32) / 32768.0; + let s2 = (sample[clamp(pos + 1, 0, sample.len() - 1)] as f32) / 32768.0; + let s3 = (sample[clamp(pos + 2, 0, sample.len() - 1)] as f32) / 32768.0; + let s4 = (sample[pos.saturating_sub(1)] as f32) / 32768.0; - //let s = cubic_interp(s1, s2, s4, s3, state.1.fract()) * 32768.0; - let s = sample[pos] as f32; + let s = cubic_interp(s1, s2, s4, s3, state.1.fract()) * 32768.0; + // let s = sample[pos] as f32; let sam = (*result ^ 0x8000) as i16; *result = sam.saturating_add(s as i16) as u16 ^ 0x8000;