This commit is contained in:
gallant 2022-05-22 07:02:13 -05:00
parent 1b890d73eb
commit 6a08149216
5 changed files with 51 additions and 22 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
MesloLGS.ttf Normal file

Binary file not shown.

BIN
grass.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -1,35 +1,35 @@
use cat_box::{draw_text, Game, Sprite, SpriteCollection, get_keyboard_state};
use std::{thread, time};
use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text};
use std::{thread};
use sdl2::keyboard::Scancode;
struct state {
struct State {
running: bool,
jumping: bool
}
fn main() {
let game = Game::new("Running", 500, 500);
//main sprite introductions
let mut i = 255u8;
let mut sprites = SpriteCollection::new();
let mut background = 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();
let sun = Sprite::new("sun.png", 50, 50).unwrap();
let grass = Sprite::new("grass.png", 250, 450).unwrap();
sprites.push(run1);
sprites.push(run2);
background.push(sun);
background.push(grass);
/*
sprites.push(stand);
let guy = state {
*/
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;
@ -40,13 +40,40 @@ fn main() {
i=200;
}
let (x,y) = run1.position();
if x < 0 {
run1.translate((x*-1+5,0));
} else if x > 500 {
run1.translate((500-x-5,0));
}
if y < 0{
run1.translate((0,y*1-5))
}else if y > 320 {
run1.translate((0,5));
}
draw_text(
ctx,
format!("x is {} and y is {}", x, y),
"MesloLGS.ttf",
30,
(100,100),
cat_box::TextMode::Shaded {
foreground: (255, 255, 255),
background: (0, 0, 0),
},
).unwrap();
for key in keys {
let state = match key {
Scancode::Left | Scancode::Right => 0,
_ => 2,
_ => 0,
};
let offset = match key {
Scancode::Escape => {
Scancode::Escape | Scancode::Q => {
game.terminate();
(0, 0)
}
@ -57,13 +84,15 @@ fn main() {
_ => (0, 0),
};
let spriteindex = sprites.get_mut(state).unwrap();
spriteindex.translate(offset);
run1.translate(offset);
}
ctx.set_background_colour(129, 201, i);
sprites.draw(ctx).unwrap();
background.draw(ctx).unwrap();
run1.draw(ctx).unwrap();
}).unwrap();
}

BIN
sun.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B