use game::Game;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::OpenGL;
use piston::event_loop::{EventSettings, Events};
use piston::input::{RenderEvent, UpdateEvent};
use piston::window::WindowSettings;
use piston::{ButtonEvent, ButtonState, EventLoop};
mod color;
mod config;
mod food;
mod game;
mod position;
mod snake;
fn main() {
let opengl = OpenGL::V3_2;
let mut window: Window = WindowSettings::new(
"Snakesss",
[config::WINDOW_HEIGHT, config::WINDOW_WIDTH],
)
.graphics_api(opengl)
.exit_on_esc(true)
.build()
.unwrap();
let mut game = Game::new(opengl);
let mut events = Events::new(EventSettings::new()).ups(16);
while let Some(e) = events.next(&mut window) {
if let Some(args) = e.render_args() {
game.render(&args);
}
if let Some(k) = e.button_args() {
if k.state == ButtonState::Press {
if game.check_button(&k.button) {
break;
}
}
}
if e.update_args().is_some() {
game.update();
}
}
}