50 lines
980 B
Rust
50 lines
980 B
Rust
pub mod map;
|
|
pub mod sound_effects;
|
|
pub mod sound_output;
|
|
|
|
pub use map::Map;
|
|
pub use sound_effects::SoundEffects;
|
|
pub use sound_output::SoundOutput;
|
|
|
|
use crate::constants::CLOCK_PERIOD;
|
|
use std::time::{Duration, Instant};
|
|
|
|
#[derive(Default)]
|
|
pub struct LevelNumber(pub u32);
|
|
|
|
#[derive(Default)]
|
|
pub struct ShowDebugInfo(pub bool);
|
|
|
|
pub struct Clock {
|
|
pub last_ticked: Instant,
|
|
pub has_ticked: bool,
|
|
pub ticks: u128,
|
|
}
|
|
|
|
impl Clock {
|
|
pub fn try_tick(&mut self) {
|
|
if Instant::now() - self.last_ticked > Duration::from_secs_f32(CLOCK_PERIOD) {
|
|
self.tick();
|
|
} else {
|
|
self.has_ticked = false;
|
|
}
|
|
}
|
|
|
|
pub fn force_tick(&mut self) {
|
|
self.tick();
|
|
}
|
|
|
|
fn tick(&mut self) {
|
|
self.has_ticked = true;
|
|
self.last_ticked = Instant::now();
|
|
self.ticks += 1;
|
|
}
|
|
}
|
|
|
|
pub struct Stats {
|
|
pub score: u32,
|
|
pub gems: u32,
|
|
pub whips: u32,
|
|
pub teleports: u32,
|
|
pub keys: u32,
|
|
}
|