-
Notifications
You must be signed in to change notification settings - Fork 35
/
main.rs
60 lines (48 loc) · 1.37 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
extern crate glutin_window;
extern crate graphics;
extern crate itertools;
extern crate opengl_graphics;
extern crate piston;
extern crate rand;
mod drawing;
mod game;
mod models;
mod traits;
use glutin_window::GlutinWindow;
use opengl_graphics::{GlGraphics, OpenGL};
use piston::event::{Event, Events, EventLoop, RenderEvent};
use piston::input::{Button, Input};
use piston::window::WindowSettings;
use drawing::Size;
use game::Game;
fn main() {
// Initialization stuff
let opengl = OpenGL::_3_2;
let window: GlutinWindow =
WindowSettings::new("Rocket", [1024, 600])
.exit_on_esc(true)
.opengl(opengl)
.samples(8)
.into();
let mut gl = GlGraphics::new(opengl);
// The game object
let mut game = Game::new(Size::new(1024.0, 600.0));
// Event handling
for e in window.events().ups(60).max_fps(60) {
match e {
Event::Input(Input::Press(Button::Keyboard(key))) => {
game.key_press(key);
}
Event::Input(Input::Release(Button::Keyboard(key))) => {
game.key_release(key);
}
Event::Render(args) => {
gl.draw(args.viewport(), |c, g| game.render(c, g));
}
Event::Update(args) => {
game.update(args.dt);
}
_ => {}
}
}
}