Include assets directly (except for font)
This commit is contained in:
parent
16a32372ee
commit
d49b4bc683
5
.cargo/config.toml
Normal file
5
.cargo/config.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
[source]
|
||||
[source.mirror]
|
||||
registry = "https://git.karx.xyz/gallant/crates.io-index.git"
|
||||
[source.crates-io]
|
||||
replace-with = "mirror"
|
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -10,9 +10,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||
|
||||
[[package]]
|
||||
name = "cat-box"
|
||||
version = "0.1.6"
|
||||
version = "22.6.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24bda0d6fb9dc5a286c9afe6286b1de1f3fe7175310b4b0c2c34174fccafbd19"
|
||||
checksum = "718fced54b0fc65b4c154bad8cbd2826447a91a2c2d3980a94cd7e2beadcb73b"
|
||||
dependencies = [
|
||||
"sdl2",
|
||||
]
|
||||
|
|
|
@ -6,7 +6,7 @@ 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 = "22.6.21"
|
||||
rand = "0.8.5"
|
||||
sdl2 = "0.35.2"
|
||||
|
||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -29,7 +29,7 @@ fn main() {
|
|||
|
||||
let mut snake = SpriteCollection::with_capacity(snake_boxes.len());
|
||||
for (x, y) in snake_boxes {
|
||||
let s = Sprite::new("snakecell.png", x * 37, y * 37).unwrap();
|
||||
let s = Sprite::from_bytes(include_bytes!("../snakecell.png"), x * 37, y * 37).unwrap();
|
||||
snake.push(s);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ fn main() {
|
|||
let x = thread_rng().gen_range(0..=27);
|
||||
let y = thread_rng().gen_range(0..=27);
|
||||
|
||||
Sprite::new("apple.png", x * 37, y * 37).unwrap()
|
||||
Sprite::from_bytes(include_bytes!("../apple.png"), x * 37, y * 37).unwrap()
|
||||
};
|
||||
|
||||
let mut dir = Direction::Left;
|
||||
|
@ -82,8 +82,8 @@ fn main() {
|
|||
let mut last_part = snake[0].position();
|
||||
|
||||
for s in snake.iter().skip(1) {
|
||||
let (lastx, lasty) = last_part;
|
||||
let (x, y) = s.position();
|
||||
let (lastx, lasty) = last_part.into();
|
||||
let (x, y) = s.position().into();
|
||||
let (xdiff, ydiff) = (lastx - x, y - lasty);
|
||||
last_part = s.position();
|
||||
s.translate((xdiff, ydiff));
|
||||
|
@ -120,19 +120,19 @@ fn main() {
|
|||
let x = thread_rng().gen_range(0..=27) * 37;
|
||||
let y = thread_rng().gen_range(0..=27) * 37;
|
||||
|
||||
let (currx, curry) = apple.position();
|
||||
let (currx, curry) = apple.position().into();
|
||||
let (xdiff, ydiff) = (x - currx, curry - y);
|
||||
apple.translate((xdiff, ydiff));
|
||||
let second_to_last = snake[snake.len() - 2].position();
|
||||
let last = snake[snake.len() - 1].position();
|
||||
|
||||
let direc = check_direction(last, second_to_last);
|
||||
let direc = check_direction(last.into(), second_to_last.into());
|
||||
|
||||
let (newx, newy) = match direc {
|
||||
Direction::Left => (last.0 - 37, last.1),
|
||||
Direction::Right => (last.0 + 37, last.1),
|
||||
Direction::Up => (last.0, last.1 - 37),
|
||||
Direction::Down => (last.0, last.1 + 37),
|
||||
Direction::Left => (last.x - 37, last.y),
|
||||
Direction::Right => (last.x + 37, last.y),
|
||||
Direction::Up => (last.x, last.y - 37),
|
||||
Direction::Down => (last.x, last.y + 37),
|
||||
};
|
||||
|
||||
let s = Sprite::new("snakecell.png", newx, newy).unwrap();
|
||||
|
@ -142,7 +142,7 @@ fn main() {
|
|||
}
|
||||
|
||||
{
|
||||
let (mut x, mut y) = snake[0].position();
|
||||
let (mut x, mut y) = snake[0].position().into();
|
||||
x /= 37;
|
||||
y /= 37;
|
||||
|
||||
|
|
Loading…
Reference in a new issue