diff --git a/.DS_Store b/.DS_Store index 092342e..4a5c561 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Cargo.lock b/Cargo.lock index 9ceb214..c83c9bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,8 +11,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cat-box" version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eea5a8bcf51d0820a0935f7dd1ad9496a43aa7dbdc9ce075272cd9d46942d726" +source = "git+https://git.karx.xyz/karx/catbox#26d6746065a2ba0640a6be3465cf73bf6d53707a" dependencies = [ "sdl2", ] diff --git a/Cargo.toml b/Cargo.toml index 228c412..3697104 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cat-box = "0.1.7" -sdl2 = "0.35.2" +cat-box = { git = "https://git.karx.xyz/karx/catbox" } +sdl2 = "0.35.2" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3d4f336..0bf426e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ -use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text,physics}; -use std::{time::{Instant}}; +use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text,physics::*,vec2::*}; +use std::{time}; use sdl2::keyboard::Scancode; -//use gravitas::{Simulation,Gravity}; /* keep track of accel, vel and pos @@ -18,7 +17,10 @@ fn main() { let mut i = 255u8; //gravity setup //let meter = 13; - let now = Instant::now(); + let now = time::Instant::now(); + let mut pos = Vec2::new(0.0,0.0); + let mut vel = Vec2::new(0.0,0.0); + let mut acc = Vec2::new(0.0,0.0); let mut background = SpriteCollection::new(); let mut run1 = Sprite::new("runner_0.png", 200, 320).unwrap(); @@ -42,6 +44,7 @@ fn main() { //sleeper agent //let sleep = thread::sleep; + //let step = time::Duration::from_millis; //main game loop game.run(|ctx|{ let keys = get_keyboard_state(ctx).keys; @@ -56,8 +59,8 @@ fn main() { let (x,y) = run1.position(); - run1.translate((0,-3)); - + + let check = check_for_collision(&run1, &background.get(1).unwrap()); if x < 0 { run1.translate((x*-1+5,0)); } else if x > 500 { @@ -69,6 +72,9 @@ fn main() { }else if y > 320 { run1.translate((0,5)); } + if !check { + run1.translate((0,-2)); + } draw_text( @@ -82,24 +88,41 @@ fn main() { background: (0, 0, 0), }, ).unwrap(); + draw_text(ctx, + format!("tf: {:?}", check), + "MesloLGS.ttf", + 15, + (250 , 200), + cat_box::TextMode::Shaded { + foreground: (255, 255, 255), + background: (0, 0, 0), + }, + ).unwrap(); for key in keys { + /*let jumper = match key { + Scancode::Up => (0,150,true), + _ => (0,0,false), + };*/ let offset = match key { Scancode::Escape | Scancode::Q => { game.terminate(); (0, 0) - } //Simulation::x(&grav,1.0) as i32 - Scancode::W | Scancode::Up => (0, 3), - Scancode::S | Scancode::Down => (0, -5), + } + + 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), }; + let offsetvec = Vec2::new(offset.0 as f32, offset.1 as f32); + pos += vel; + vel += acc; + acc = Vec2::new(0.0, -9.8) + offsetvec; + //run1.translate((pos.0)) + run1.translate((pos.x as i32,pos.y as i32)); - //if physics::check_for_collision(&run1, background.get_mut(1).unwrap()){ - run1.translate((offset.0,offset.1)); - - //}