forked from karx/snake
Draw snake onto screen
This commit is contained in:
parent
7d5baa7a4a
commit
63ab319691
BIN
snakecell.png
Normal file
BIN
snakecell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 137 B |
|
@ -3,6 +3,13 @@ use sdl2::keyboard::Scancode;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let game = Game::new("Snake", 1000, 1000);
|
let game = Game::new("Snake", 1000, 1000);
|
||||||
|
let snake_boxes: Vec<(i32, i32)> = vec![(13, 13), (14, 13)];
|
||||||
|
|
||||||
|
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();
|
||||||
|
snake.push(s);
|
||||||
|
}
|
||||||
|
|
||||||
game.run(|ctx| {
|
game.run(|ctx| {
|
||||||
let keys = get_keyboard_state(ctx).keys;
|
let keys = get_keyboard_state(ctx).keys;
|
||||||
|
@ -12,6 +19,8 @@ fn main() {
|
||||||
game.terminate();
|
game.terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
snake.draw(ctx).unwrap();
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue