diff --git a/Cargo.lock b/Cargo.lock index bd464fe..d45e233 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bitflags" version = "1.3.2" @@ -23,6 +29,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00" +dependencies = [ + "num", + "time", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -35,12 +51,54 @@ version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-integer", + "num-iter", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + [[package]] name = "practice_game" version = "0.1.0" dependencies = [ "cat-box", "sdl2", + "timer", ] [[package]] @@ -66,8 +124,56 @@ dependencies = [ "version-compare", ] +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "timer" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9522a9ec40055e2f9e514e38d2415a496e81dbfc1ece15d98d2fe55c44946b3" +dependencies = [ + "chrono", +] + [[package]] name = "version-compare" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 434492c..177ba22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" [dependencies] cat-box = "0.1.6" -sdl2 = "0.35.2" \ No newline at end of file +sdl2 = "0.35.2" +timer = "0.1.3" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d569fb6..fa41637 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text}; -use std::{thread}; +use std::{thread, time::{Instant, SystemTime}}; use sdl2::keyboard::Scancode; struct State { @@ -12,6 +12,11 @@ fn main() { //main sprite introductions let mut i = 255u8; + //gravity setup + let meter = 13; + let now = Instant::now(); + let mut jumped = 0; + let mut background = SpriteCollection::new(); let mut run1 = Sprite::new("runner_0.png", 200, 250).unwrap(); let sun = Sprite::new("sun.png", 50, 50).unwrap(); @@ -29,7 +34,7 @@ fn main() { }; //sleeper agent - let _sleep = thread::sleep; + let sleep = thread::sleep; //main game loop game.run(|ctx|{ let keys = get_keyboard_state(ctx).keys; @@ -54,12 +59,16 @@ fn main() { }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 {}", x, y), + format!("x is {} and y is {}, {:?} Seconds have passed", x, y, now.elapsed().as_secs()), "MesloLGS.ttf", - 30, - (100,100), + 15, + (250,100), cat_box::TextMode::Shaded { foreground: (255, 255, 255), background: (0, 0, 0), @@ -68,24 +77,32 @@ fn main() { for key in keys { - let state = match key { - Scancode::Left | Scancode::Right => 0, - _ => 0, - }; let offset = match key { Scancode::Escape | Scancode::Q => { 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); + + 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; + } }