gallant 7 months ago
parent 1b890d73eb
commit 6a08149216
  1. BIN
      .DS_Store
  2. BIN
      MesloLGS.ttf
  3. BIN
      grass.png
  4. 73
      src/main.rs
  5. BIN
      sun.png

BIN
.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

@ -1,52 +1,79 @@
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();
sprites.push(run1);
sprites.push(run2);
let sun = Sprite::new("sun.png", 50, 50).unwrap();
let grass = Sprite::new("grass.png", 250, 450).unwrap();
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;
if i<200{
i = i + 10;
}else if i >= 255{
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();
ctx.set_background_colour(129, 201, i);
background.draw(ctx).unwrap();
run1.draw(ctx).unwrap();
}).unwrap();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

Loading…
Cancel
Save