Dependency update

master
Levi Pearson 2018-06-28 20:03:52 -06:00
parent eb1a4830ca
commit ed3f393b81
5 changed files with 712 additions and 378 deletions

1024
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -10,4 +10,5 @@ authors = [
name = "rust-pilot" name = "rust-pilot"
[dependencies] [dependencies]
piston_window = "0.40.0" piston_window = "*"
#"0.40.0"

View File

@ -17,28 +17,26 @@ impl Controls {
} }
} }
pub fn update(&mut self, inp: Input) { pub fn update(&mut self, inp: &Event) {
match inp { if let Some(b) = inp.press_args() {
Input::Press(b) => { match b {
match b { Button::Keyboard(Key::Up) => { self.up_d = true; }
Button::Keyboard(Key::Up) => { self.up_d = true; } Button::Keyboard(Key::Down) => { self.down_d = true; }
Button::Keyboard(Key::Down) => { self.down_d = true; } Button::Keyboard(Key::Left) => { self.left_d = true; }
Button::Keyboard(Key::Left) => { self.left_d = true; } Button::Keyboard(Key::Right) => { self.right_d = true; }
Button::Keyboard(Key::Right) => { self.right_d = true; } _ => {}
_ => {}
}
} }
Input::Release(b) => {
match b { }
Button::Keyboard(Key::Up) => { self.up_d = false; } if let Some(b) = inp.release_args() {
Button::Keyboard(Key::Down) => { self.down_d = false; } match b {
Button::Keyboard(Key::Left) => { self.left_d = false; } Button::Keyboard(Key::Up) => { self.up_d = false; }
Button::Keyboard(Key::Right) => { self.right_d = false; } Button::Keyboard(Key::Down) => { self.down_d = false; }
Button::Keyboard(Key::Space) => { self.fire = true; } Button::Keyboard(Key::Left) => { self.left_d = false; }
_ => {} Button::Keyboard(Key::Right) => { self.right_d = false; }
} Button::Keyboard(Key::Space) => { self.fire = true; }
_ => {}
} }
_ => {}
} }
} }

View File

@ -60,9 +60,11 @@ impl Game {
} }
} }
pub fn render(&mut self, args: RenderArgs, w: PistonWindow) { pub fn render<GE>(&mut self, args: RenderArgs, w: &mut PistonWindow, e: &GE) where
GE: GenericEvent
{
w.draw_2d(|context, gl| { w.draw_2d(e, |context, gl| {
draw_background(gl); draw_background(gl);
let ds = context.draw_state.blend(Blend::Alpha); let ds = context.draw_state.blend(Blend::Alpha);
@ -105,7 +107,7 @@ impl Game {
self.camera.follow(self.player.position, &self.map); self.camera.follow(self.player.position, &self.map);
} }
pub fn input(&mut self, inp: Input) { pub fn input(&mut self, inp: &Event) {
self.controls.update(inp); self.controls.update(inp);
} }
} }

View File

@ -9,7 +9,7 @@ const XDIM: u32 = 600;
const YDIM: u32 = 600; const YDIM: u32 = 600;
fn main() { fn main() {
let window: PistonWindow = WindowSettings::new( let mut window: PistonWindow = WindowSettings::new(
"rust-pilot", "rust-pilot",
[XDIM, YDIM] [XDIM, YDIM]
) )
@ -21,18 +21,19 @@ fn main() {
// Create a new game and run it. // Create a new game and run it.
let mut game = Game::new(XDIM as Scalar, YDIM as Scalar); let mut game = Game::new(XDIM as Scalar, YDIM as Scalar);
for e in window { while let Some(e) = window.next() {
match e.event { match e {
Some(Event::Update(upd)) => { Event::Loop(Loop::Update(upd)) => {
game.update(upd); game.update(upd);
} }
Some(Event::Render(ren)) => { Event::Loop(Loop::Render(ren)) => {
game.render(ren, e); game.render(ren, &mut window, &e);
} }
Some(Event::Input(inp)) => { Event::Input(inp) => {
game.input(inp); let ev = Event::Input(inp);
game.input(&ev);
} }
_ => { _ => {