-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
39 lines (33 loc) · 953 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mod draw;
mod game;
mod snake;
use piston_window::types::Color;
use piston_window::*;
use crate::draw::to_coord_u32;
use crate::game::Game;
const BACK_COLOR: Color = [0.5, 0.5, 0.5, 1.0];
fn main() {
let (width, height) = (30, 30);
let mut window: PistonWindow =
WindowSettings::new("Snake", [to_coord_u32(width), to_coord_u32(height)])
.exit_on_esc(true)
.build()
.unwrap();
// println!(
// "********************** device info: {:?}",
// window.device.get_info()
// );
let mut game = Game::new(width, height);
while let Some(event) = window.next() {
if let Some(Button::Keyboard(key)) = event.press_args() {
game.key_pressed(key);
}
window.draw_2d(&event, |c, g, _| {
clear(BACK_COLOR, g);
game.draw(&c, g);
});
event.update(|arg| {
game.update(arg.dt);
});
}
}