forked from karx/catbox
timer lolz
This commit is contained in:
parent
71aa76b7c2
commit
8a33c0f42e
|
@ -12,7 +12,7 @@ exclude = ["src/main.rs"]
|
||||||
|
|
||||||
[dependencies.sdl2]
|
[dependencies.sdl2]
|
||||||
version = "0.35.2"
|
version = "0.35.2"
|
||||||
features = ["image", "ttf"]
|
features = ["image", "ttf", "bundled"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rodio = { version = "0.15.0", optional = true}
|
rodio = { version = "0.15.0", optional = true}
|
||||||
|
|
BIN
SDL2_image.dll
Normal file
BIN
SDL2_image.dll
Normal file
Binary file not shown.
BIN
SDL2_ttf.dll
Normal file
BIN
SDL2_ttf.dll
Normal file
Binary file not shown.
10
src/lib.rs
10
src/lib.rs
|
@ -113,6 +113,7 @@ use std::{
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
path::Path,
|
path::Path,
|
||||||
slice::IterMut,
|
slice::IterMut,
|
||||||
|
time::Instant,
|
||||||
};
|
};
|
||||||
use vec2::Vec2Int;
|
use vec2::Vec2Int;
|
||||||
|
|
||||||
|
@ -706,6 +707,7 @@ pub struct Game {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
/// The height of the opened window
|
/// The height of the opened window
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
pub time: Cell<Instant>,
|
||||||
stopped: Cell<bool>,
|
stopped: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -725,9 +727,17 @@ impl Game {
|
||||||
title: title.to_string(),
|
title: title.to_string(),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
time: Instant::now().into(),
|
||||||
stopped: Cell::new(false),
|
stopped: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn step(&self) -> u128 {
|
||||||
|
let a = self.time.get().elapsed().as_millis().clone();
|
||||||
|
a
|
||||||
|
}
|
||||||
|
pub fn t_reset(&self) {
|
||||||
|
self.time.set(Instant::now());
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs the game. Note: this method blocks, as it uses an infinite loop.
|
/// Runs the game. Note: this method blocks, as it uses an infinite loop.
|
||||||
///
|
///
|
||||||
|
|
|
@ -22,6 +22,7 @@ fn main() {
|
||||||
#[cfg(feature = "audio")]
|
#[cfg(feature = "audio")]
|
||||||
cat_box::play("output.mp3", 120);
|
cat_box::play("output.mp3", 120);
|
||||||
game.run(|ctx| {
|
game.run(|ctx| {
|
||||||
|
if game.step() >= 1 {
|
||||||
i = (i + 1) % 255;
|
i = (i + 1) % 255;
|
||||||
ctx.set_background_colour(i as u8, 64, 255);
|
ctx.set_background_colour(i as u8, 64, 255);
|
||||||
|
|
||||||
|
@ -82,6 +83,9 @@ fn main() {
|
||||||
println!("Sprites collided! {}", i);
|
println!("Sprites collided! {}", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
game.t_reset();
|
||||||
|
}
|
||||||
s2.draw(ctx).unwrap();
|
s2.draw(ctx).unwrap();
|
||||||
s.draw(ctx).unwrap();
|
s.draw(ctx).unwrap();
|
||||||
coll.draw(ctx).unwrap();
|
coll.draw(ctx).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue