diff --git a/Cargo.lock b/Cargo.lock index d45e233..1553d5f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,9 +16,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cat-box" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24bda0d6fb9dc5a286c9afe6286b1de1f3fe7175310b4b0c2c34174fccafbd19" +checksum = "eea5a8bcf51d0820a0935f7dd1ad9496a43aa7dbdc9ce075272cd9d46942d726" dependencies = [ "sdl2", ] diff --git a/Cargo.toml b/Cargo.toml index 177ba22..280927d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cat-box = "0.1.6" +cat-box = "0.1.7" sdl2 = "0.35.2" timer = "0.1.3" \ No newline at end of file diff --git a/car.gif b/car.gif new file mode 100644 index 0000000..5e7cee3 Binary files /dev/null and b/car.gif differ diff --git a/src/main.rs b/src/main.rs index fa41637..2298e80 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,28 @@ use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text}; -use std::{thread, time::{Instant, SystemTime}}; +use std::{time::{Instant}}; use sdl2::keyboard::Scancode; -struct State { - running: bool, - jumping: bool -} - +/* +keep track of accel, vel and pos +every tick: +1. pos += vel +2. vel += accel +3. accel = (calculate from arrow keys) + (0, -9.8) +*/ fn main() { let game = Game::new("Running", 500, 500); //main sprite introductions let mut i = 255u8; //gravity setup - let meter = 13; + //let meter = 13; let now = Instant::now(); - let mut jumped = 0; + + + //let (mut pos, mut vel, mut accel) = (20.0,0.0,-9.8); let mut background = SpriteCollection::new(); - let mut run1 = Sprite::new("runner_0.png", 200, 250).unwrap(); + let mut run1 = Sprite::new("runner_0.png", 200, 320).unwrap(); let sun = Sprite::new("sun.png", 50, 50).unwrap(); let grass = Sprite::new("grass.png", 250, 450).unwrap(); @@ -27,18 +31,20 @@ fn main() { background.push(grass); /* sprites.push(stand); - */ + let _guy = State { running: false, jumping: false - }; + };*/ //sleeper agent - let sleep = thread::sleep; + //let sleep = thread::sleep; //main game loop game.run(|ctx|{ let keys = get_keyboard_state(ctx).keys; + + if i<200{ i = i + 10; }else if i >= 255{ @@ -54,15 +60,13 @@ fn main() { } else if x > 500 { run1.translate((500-x-5,0)); } + if y < 0{ - run1.translate((0,y*1-5)) + run1.translate((0,y - run1.rect.height() as i32)) }else if y > 320 { run1.translate((0,5)); } - while y != 320 && y < 325 { - run1.translate((0,-1)); - break - } + draw_text( ctx, format!("x is {} and y is {}, {:?} Seconds have passed", x, y, now.elapsed().as_secs()), @@ -74,7 +78,6 @@ fn main() { background: (0, 0, 0), }, ).unwrap(); - for key in keys { let offset = match key { @@ -82,27 +85,15 @@ fn main() { 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), }; - run1.translate(offset); + run1.translate((offset.0,offset.1 )); - let jumpy = match key { - Scancode::W | Scancode::Up => (0, 120), - _ => (0,0), - }; - - while jumped == 0{ - run1.translate(jumpy); - - jumped = 1; - } - if y == 320 { - jumped = 0; - } + }