catbox moment

main
gallant 6 months ago
parent 21bda8d268
commit ab6eb6f4c3
  1. BIN
      .DS_Store
  2. 3
      Cargo.lock
  3. 4
      Cargo.toml
  4. 49
      src/main.rs

BIN
.DS_Store vendored

Binary file not shown.

3
Cargo.lock generated

@ -11,8 +11,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cat-box"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eea5a8bcf51d0820a0935f7dd1ad9496a43aa7dbdc9ce075272cd9d46942d726"
source = "git+https://git.karx.xyz/karx/catbox#26d6746065a2ba0640a6be3465cf73bf6d53707a"
dependencies = [
"sdl2",
]

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

@ -1,8 +1,7 @@
use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text,physics};
use std::{time::{Instant}};
use cat_box::{Game, Sprite, SpriteCollection, get_keyboard_state, draw_text,physics::*,vec2::*};
use std::{time};
use sdl2::keyboard::Scancode;
//use gravitas::{Simulation,Gravity};
/*
keep track of accel, vel and pos
@ -18,7 +17,10 @@ fn main() {
let mut i = 255u8;
//gravity setup
//let meter = 13;
let now = Instant::now();
let now = time::Instant::now();
let mut pos = Vec2::new(0.0,0.0);
let mut vel = Vec2::new(0.0,0.0);
let mut acc = Vec2::new(0.0,0.0);
let mut background = SpriteCollection::new();
let mut run1 = Sprite::new("runner_0.png", 200, 320).unwrap();
@ -42,6 +44,7 @@ fn main() {
//sleeper agent
//let sleep = thread::sleep;
//let step = time::Duration::from_millis;
//main game loop
game.run(|ctx|{
let keys = get_keyboard_state(ctx).keys;
@ -56,8 +59,8 @@ fn main() {
let (x,y) = run1.position();
run1.translate((0,-3));
let check = check_for_collision(&run1, &background.get(1).unwrap());
if x < 0 {
run1.translate((x*-1+5,0));
} else if x > 500 {
@ -69,6 +72,9 @@ fn main() {
}else if y > 320 {
run1.translate((0,5));
}
if !check {
run1.translate((0,-2));
}
draw_text(
@ -82,24 +88,41 @@ fn main() {
background: (0, 0, 0),
},
).unwrap();
draw_text(ctx,
format!("tf: {:?}", check),
"MesloLGS.ttf",
15,
(250 , 200),
cat_box::TextMode::Shaded {
foreground: (255, 255, 255),
background: (0, 0, 0),
},
).unwrap();
for key in keys {
/*let jumper = match key {
Scancode::Up => (0,150,true),
_ => (0,0,false),
};*/
let offset = match key {
Scancode::Escape | Scancode::Q => {
game.terminate();
(0, 0)
} //Simulation::x(&grav,1.0) as i32
Scancode::W | Scancode::Up => (0, 3),
Scancode::S | Scancode::Down => (0, -5),
}
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),
};
let offsetvec = Vec2::new(offset.0 as f32, offset.1 as f32);
pos += vel;
vel += acc;
acc = Vec2::new(0.0, -9.8) + offsetvec;
//run1.translate((pos.0))
run1.translate((pos.x as i32,pos.y as i32));
//if physics::check_for_collision(&run1, background.get_mut(1).unwrap()){
run1.translate((offset.0,offset.1));
//}

Loading…
Cancel
Save