gallant 6 months ago
parent cc9a59784d
commit da847a73b2
  1. 4
      Cargo.lock
  2. 2
      Cargo.toml
  3. BIN
      car.gif
  4. 57
      src/main.rs

4
Cargo.lock generated

@ -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",
]

@ -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"

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

@ -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);
let jumpy = match key {
Scancode::W | Scancode::Up => (0, 120),
_ => (0,0),
};
run1.translate((offset.0,offset.1 ));
while jumped == 0{
run1.translate(jumpy);
jumped = 1;
}
if y == 320 {
jumped = 0;
}
}

Loading…
Cancel
Save