Compare commits

..

2 Commits

2 changed files with 29 additions and 22 deletions

View File

@@ -75,19 +75,17 @@ pub fn main() {
// TODO: Fix key repeat delay issues by using VecDeque for instant key repeat // TODO: Fix key repeat delay issues by using VecDeque for instant key repeat
for event in event_pump.poll_iter() { for event in event_pump.poll_iter() {
match event { match event {
Event::Window { win_event, .. } => { Event::Window { win_event, .. } => match win_event {
match win_event {
WindowEvent::Hidden => { WindowEvent::Hidden => {
event!(tracing::Level::DEBUG, "Window hidden"); event!(tracing::Level::DEBUG, "Window hidden");
shown = false; shown = false;
}, }
WindowEvent::Shown => { WindowEvent::Shown => {
event!(tracing::Level::DEBUG, "Window shown"); event!(tracing::Level::DEBUG, "Window shown");
shown = true; shown = true;
}, }
_ => {} _ => {}
} },
}
// Handle quitting keys or window close // Handle quitting keys or window close
Event::Quit { .. } Event::Quit { .. }
| Event::KeyDown { | Event::KeyDown {
@@ -123,11 +121,15 @@ pub fn main() {
if start.elapsed() < loop_time { if start.elapsed() < loop_time {
let time = loop_time.saturating_sub(start.elapsed()); let time = loop_time.saturating_sub(start.elapsed());
#[cfg(not(target_os = "emscripten"))] { if time != Duration::ZERO {
#[cfg(not(target_os = "emscripten"))]
{
spin_sleep::sleep(time); spin_sleep::sleep(time);
} }
#[cfg(target_os = "emscripten")] { #[cfg(target_os = "emscripten")]
thread::sleep(time); {
std::thread::sleep(time);
}
} }
sleep_time += time; sleep_time += time;
} else { } else {

View File

@@ -34,11 +34,11 @@ impl Pacman<'_> {
position: Map::cell_to_pixel(starting_position), position: Map::cell_to_pixel(starting_position),
direction: Direction::Right, direction: Direction::Right,
next_direction: None, next_direction: None,
speed: 2, speed: 3,
map, map,
stopped: false, stopped: false,
modulation: SimpleTickModulator::new(0.9333), modulation: SimpleTickModulator::new(1.0),
sprite: AnimatedTexture::new(atlas, 4, 3, 32, 32, Some((-4, -4))), sprite: AnimatedTexture::new(atlas, 2, 3, 32, 32, Some((-4, -4))),
} }
} }
@@ -77,6 +77,11 @@ impl Pacman<'_> {
self.next_direction = None; self.next_direction = None;
} }
} }
fn internal_position_even(&self) -> (u32, u32) {
let (x, y ) = self.internal_position();
((x / 2u32) * 2u32, (y / 2u32) * 2u32)
}
} }
impl Entity for Pacman<'_> { impl Entity for Pacman<'_> {
@@ -104,7 +109,7 @@ impl Entity for Pacman<'_> {
} }
fn tick(&mut self) { fn tick(&mut self) {
let can_change = self.internal_position() == (0, 0); let can_change = self.internal_position_even() == (0, 0);
if can_change { if can_change {
self.handle_requested_direction(); self.handle_requested_direction();