mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 18:07:56 -06:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 40acffafd1 | |||
| 2187212b7c |
36
src/main.rs
36
src/main.rs
@@ -75,19 +75,17 @@ pub fn main() {
|
||||
// TODO: Fix key repeat delay issues by using VecDeque for instant key repeat
|
||||
for event in event_pump.poll_iter() {
|
||||
match event {
|
||||
Event::Window { win_event, .. } => {
|
||||
match win_event {
|
||||
WindowEvent::Hidden => {
|
||||
event!(tracing::Level::DEBUG, "Window hidden");
|
||||
shown = false;
|
||||
},
|
||||
WindowEvent::Shown => {
|
||||
event!(tracing::Level::DEBUG, "Window shown");
|
||||
shown = true;
|
||||
},
|
||||
_ => {}
|
||||
Event::Window { win_event, .. } => match win_event {
|
||||
WindowEvent::Hidden => {
|
||||
event!(tracing::Level::DEBUG, "Window hidden");
|
||||
shown = false;
|
||||
}
|
||||
}
|
||||
WindowEvent::Shown => {
|
||||
event!(tracing::Level::DEBUG, "Window shown");
|
||||
shown = true;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
// Handle quitting keys or window close
|
||||
Event::Quit { .. }
|
||||
| Event::KeyDown {
|
||||
@@ -123,11 +121,15 @@ pub fn main() {
|
||||
|
||||
if start.elapsed() < loop_time {
|
||||
let time = loop_time.saturating_sub(start.elapsed());
|
||||
#[cfg(not(target_os = "emscripten"))] {
|
||||
spin_sleep::sleep(time);
|
||||
}
|
||||
#[cfg(target_os = "emscripten")] {
|
||||
thread::sleep(time);
|
||||
if time != Duration::ZERO {
|
||||
#[cfg(not(target_os = "emscripten"))]
|
||||
{
|
||||
spin_sleep::sleep(time);
|
||||
}
|
||||
#[cfg(target_os = "emscripten")]
|
||||
{
|
||||
std::thread::sleep(time);
|
||||
}
|
||||
}
|
||||
sleep_time += time;
|
||||
} else {
|
||||
|
||||
@@ -34,11 +34,11 @@ impl Pacman<'_> {
|
||||
position: Map::cell_to_pixel(starting_position),
|
||||
direction: Direction::Right,
|
||||
next_direction: None,
|
||||
speed: 2,
|
||||
speed: 3,
|
||||
map,
|
||||
stopped: false,
|
||||
modulation: SimpleTickModulator::new(0.9333),
|
||||
sprite: AnimatedTexture::new(atlas, 4, 3, 32, 32, Some((-4, -4))),
|
||||
modulation: SimpleTickModulator::new(1.0),
|
||||
sprite: AnimatedTexture::new(atlas, 2, 3, 32, 32, Some((-4, -4))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,11 @@ impl Pacman<'_> {
|
||||
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<'_> {
|
||||
@@ -104,7 +109,7 @@ impl Entity for Pacman<'_> {
|
||||
}
|
||||
|
||||
fn tick(&mut self) {
|
||||
let can_change = self.internal_position() == (0, 0);
|
||||
let can_change = self.internal_position_even() == (0, 0);
|
||||
|
||||
if can_change {
|
||||
self.handle_requested_direction();
|
||||
@@ -120,7 +125,7 @@ impl Entity for Pacman<'_> {
|
||||
self.stopped = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !self.stopped && self.modulation.next() {
|
||||
let speed = self.speed as i32;
|
||||
match self.direction {
|
||||
|
||||
Reference in New Issue
Block a user