doesn't work

This commit is contained in:
gallant 2022-05-21 10:57:13 -05:00
parent 571f65e9a0
commit 5f1333c22f
4 changed files with 42 additions and 10 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

1
Cargo.lock generated
View File

@ -40,7 +40,6 @@ name = "practice_game"
version = "0.1.0"
dependencies = [
"cat-box",
"sdl2",
]
[[package]]

View File

@ -6,5 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cat-box = "0.1.6"
sdl2 = "0.35.2"
cat-box = "0.1.6"

View File

@ -1,27 +1,61 @@
use cat_box::{draw_text, Game, Sprite, SpriteCollection};
use cat_box::{draw_text, Game, Sprite, SpriteCollection, get_keyboard_state};
use std::{thread, time};
struct state {
running: bool,
jumping: bool
}
fn main() {
let game = Game::new("Running", 500, 500);
//main sprite introductions
let mut i = 255u8;
let mut running = SpriteCollection::new();
let mut run1 = Sprite::new("runner_0.png", 250, 250).unwrap();
let mut run2 = Sprite::new("runner_1.png", 250, 250).unwrap();
let mut stand = Sprite::new("runner_s.png", 250, 250).unwrap();
running.push(run1);
let mut sprites = SpriteCollection::new();
let mut run1 = Sprite::new("runner_0.png", 200, 250).unwrap();
let mut run2 = Sprite::new("runner_1.png", 300, 250).unwrap();
let mut stand = Sprite::new("runner_s.png", 400, 250).unwrap();
sprites.push(run1);
sprites.push(run2);
sprites.push(stand);
let guy = state {
running: false,
jumping: false
};
//sleeper agent
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{
i=200;
}
/*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),
};
}*/
ctx.set_background_colour( 129, 201, i);
running.draw(ctx).unwrap();
sprites.draw(ctx).unwrap();
}).unwrap();
}