diff --git a/Cargo.toml b/Cargo.toml index 49b5993..8c9751d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ exclude = ["src/main.rs"] [dependencies.sdl2] version = "0.35.2" -features = ["image", "ttf"] +features = ["image", "ttf", "bundled"] [dependencies] rodio = { version = "0.15.0", optional = true} diff --git a/SDL2.dll b/SDL2.dll new file mode 100644 index 0000000..0f91bd6 Binary files /dev/null and b/SDL2.dll differ diff --git a/SDL2_image.dll b/SDL2_image.dll new file mode 100644 index 0000000..277e981 Binary files /dev/null and b/SDL2_image.dll differ diff --git a/SDL2_ttf.dll b/SDL2_ttf.dll new file mode 100644 index 0000000..24253fa Binary files /dev/null and b/SDL2_ttf.dll differ diff --git a/src/lib.rs b/src/lib.rs index 0c31acc..f5cfe0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,6 +113,7 @@ use std::{ ops::{Deref, DerefMut}, path::Path, slice::IterMut, + time::Instant, }; use vec2::Vec2Int; @@ -706,6 +707,7 @@ pub struct Game { pub width: u32, /// The height of the opened window pub height: u32, + pub time: Cell, stopped: Cell, } @@ -725,9 +727,17 @@ impl Game { title: title.to_string(), width, height, + time: Instant::now().into(), 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. /// diff --git a/src/main.rs b/src/main.rs index 4980e07..c70fc6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,69 +22,73 @@ fn main() { #[cfg(feature = "audio")] cat_box::play("output.mp3", 120); game.run(|ctx| { - i = (i + 1) % 255; - ctx.set_background_colour(i as u8, 64, 255); + if game.step() >= 1 { + i = (i + 1) % 255; + ctx.set_background_colour(i as u8, 64, 255); - draw_text( - ctx, - format!("i is {}", i), - "MesloLGS NF Regular.ttf", - 72, - (300, 300), - cat_box::TextMode::Shaded { - foreground: (255, 255, 255), - background: (0, 0, 0), - }, - ) - .unwrap(); + draw_text( + ctx, + format!("i is {}", i), + "MesloLGS NF Regular.ttf", + 72, + (300, 300), + cat_box::TextMode::Shaded { + foreground: (255, 255, 255), + background: (0, 0, 0), + }, + ) + .unwrap(); - let (start_x, start_y) = s.position().into(); - let m = get_mouse_state(ctx); - let x_diff = m.x - start_x; - let y_diff = m.y - start_y; - - let angle = f64::from(y_diff).atan2(f64::from(x_diff)); - s.set_angle(angle.to_degrees()); - - for spr in coll.iter() { - let (start_x, start_y) = spr.position().into(); + let (start_x, start_y) = s.position().into(); let m = get_mouse_state(ctx); let x_diff = m.x - start_x; let y_diff = m.y - start_y; let angle = f64::from(y_diff).atan2(f64::from(x_diff)); - spr.set_angle(angle.to_degrees()); - } - - let keys = get_keyboard_state(ctx).keys; - - for key in keys { - let offset = match key { - Scancode::Escape => { - game.terminate(); - (0, 0) - } - Scancode::W | Scancode::Up => (0, 5), - Scancode::S | Scancode::Down => (0, -5), - Scancode::A | Scancode::Left => (-5, 0), - Scancode::D | Scancode::Right => (5, 0), - _ => (0, 0), - }; - - s.translate(offset); + s.set_angle(angle.to_degrees()); for spr in coll.iter() { - spr.translate(offset); + let (start_x, start_y) = spr.position().into(); + let m = get_mouse_state(ctx); + let x_diff = m.x - start_x; + let y_diff = m.y - start_y; + + let angle = f64::from(y_diff).atan2(f64::from(x_diff)); + spr.set_angle(angle.to_degrees()); } - } - if !cat_box::physics::check_for_collision_with_collection(&s2, &coll).is_empty() { - println!("Sprites collided! {}", i); - } + let keys = get_keyboard_state(ctx).keys; - s2.draw(ctx).unwrap(); - s.draw(ctx).unwrap(); - coll.draw(ctx).unwrap(); + for key in keys { + let offset = match key { + Scancode::Escape => { + game.terminate(); + (0, 0) + } + Scancode::W | Scancode::Up => (0, 5), + Scancode::S | Scancode::Down => (0, -5), + Scancode::A | Scancode::Left => (-5, 0), + Scancode::D | Scancode::Right => (5, 0), + _ => (0, 0), + }; + + s.translate(offset); + + for spr in coll.iter() { + spr.translate(offset); + } + } + + if !cat_box::physics::check_for_collision_with_collection(&s2, &coll).is_empty() { + println!("Sprites collided! {}", i); + } + + + game.t_reset(); + } + s2.draw(ctx).unwrap(); + s.draw(ctx).unwrap(); + coll.draw(ctx).unwrap(); }) .unwrap(); }