Display score
This commit is contained in:
parent
47de327e05
commit
a18db70127
BIN
ibm_bios-2y.ttf
Normal file
BIN
ibm_bios-2y.ttf
Normal file
Binary file not shown.
18
src/main.rs
18
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use cat_box::{get_keyboard_state, Game, Sprite, SpriteCollection};
|
use cat_box::{draw_text, get_keyboard_state, Game, Sprite, SpriteCollection};
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use sdl2::keyboard::Scancode;
|
use sdl2::keyboard::Scancode;
|
||||||
|
@ -39,7 +39,21 @@ fn main() {
|
||||||
|
|
||||||
let mut dir = Direction::Left;
|
let mut dir = Direction::Left;
|
||||||
|
|
||||||
|
let mut score = 0u64;
|
||||||
|
|
||||||
game.run(|ctx| {
|
game.run(|ctx| {
|
||||||
|
draw_text(
|
||||||
|
ctx,
|
||||||
|
format!("Score: {}", score),
|
||||||
|
"ibm_bios-2y.ttf",
|
||||||
|
36,
|
||||||
|
(100, 100),
|
||||||
|
cat_box::TextMode::Transparent {
|
||||||
|
colour: (255, 255, 255),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let keys = get_keyboard_state(ctx).keys;
|
let keys = get_keyboard_state(ctx).keys;
|
||||||
|
|
||||||
for key in keys {
|
for key in keys {
|
||||||
|
@ -103,6 +117,8 @@ fn main() {
|
||||||
|
|
||||||
let s = Sprite::new("snakecell.png", newx, newy).unwrap();
|
let s = Sprite::new("snakecell.png", newx, newy).unwrap();
|
||||||
snake.push(s);
|
snake.push(s);
|
||||||
|
|
||||||
|
score += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue