Dependency update
parent
eb1a4830ca
commit
ed3f393b81
File diff suppressed because it is too large
Load Diff
|
@ -10,4 +10,5 @@ authors = [
|
|||
name = "rust-pilot"
|
||||
|
||||
[dependencies]
|
||||
piston_window = "0.40.0"
|
||||
piston_window = "*"
|
||||
#"0.40.0"
|
||||
|
|
|
@ -17,28 +17,26 @@ impl Controls {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, inp: Input) {
|
||||
match inp {
|
||||
Input::Press(b) => {
|
||||
match b {
|
||||
Button::Keyboard(Key::Up) => { self.up_d = true; }
|
||||
Button::Keyboard(Key::Down) => { self.down_d = true; }
|
||||
Button::Keyboard(Key::Left) => { self.left_d = true; }
|
||||
Button::Keyboard(Key::Right) => { self.right_d = true; }
|
||||
_ => {}
|
||||
}
|
||||
pub fn update(&mut self, inp: &Event) {
|
||||
if let Some(b) = inp.press_args() {
|
||||
match b {
|
||||
Button::Keyboard(Key::Up) => { self.up_d = true; }
|
||||
Button::Keyboard(Key::Down) => { self.down_d = true; }
|
||||
Button::Keyboard(Key::Left) => { self.left_d = true; }
|
||||
Button::Keyboard(Key::Right) => { self.right_d = true; }
|
||||
_ => {}
|
||||
}
|
||||
Input::Release(b) => {
|
||||
match b {
|
||||
Button::Keyboard(Key::Up) => { self.up_d = false; }
|
||||
Button::Keyboard(Key::Down) => { self.down_d = false; }
|
||||
Button::Keyboard(Key::Left) => { self.left_d = false; }
|
||||
Button::Keyboard(Key::Right) => { self.right_d = false; }
|
||||
Button::Keyboard(Key::Space) => { self.fire = true; }
|
||||
_ => {}
|
||||
}
|
||||
|
||||
}
|
||||
if let Some(b) = inp.release_args() {
|
||||
match b {
|
||||
Button::Keyboard(Key::Up) => { self.up_d = false; }
|
||||
Button::Keyboard(Key::Down) => { self.down_d = false; }
|
||||
Button::Keyboard(Key::Left) => { self.left_d = false; }
|
||||
Button::Keyboard(Key::Right) => { self.right_d = false; }
|
||||
Button::Keyboard(Key::Space) => { self.fire = true; }
|
||||
_ => {}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
let ds = context.draw_state.blend(Blend::Alpha);
|
||||
|
@ -105,7 +107,7 @@ impl Game {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -9,7 +9,7 @@ const XDIM: u32 = 600;
|
|||
const YDIM: u32 = 600;
|
||||
|
||||
fn main() {
|
||||
let window: PistonWindow = WindowSettings::new(
|
||||
let mut window: PistonWindow = WindowSettings::new(
|
||||
"rust-pilot",
|
||||
[XDIM, YDIM]
|
||||
)
|
||||
|
@ -21,18 +21,19 @@ fn main() {
|
|||
|
||||
// Create a new game and run it.
|
||||
let mut game = Game::new(XDIM as Scalar, YDIM as Scalar);
|
||||
for e in window {
|
||||
match e.event {
|
||||
Some(Event::Update(upd)) => {
|
||||
while let Some(e) = window.next() {
|
||||
match e {
|
||||
Event::Loop(Loop::Update(upd)) => {
|
||||
game.update(upd);
|
||||
}
|
||||
|
||||
Some(Event::Render(ren)) => {
|
||||
game.render(ren, e);
|
||||
Event::Loop(Loop::Render(ren)) => {
|
||||
game.render(ren, &mut window, &e);
|
||||
}
|
||||
|
||||
Some(Event::Input(inp)) => {
|
||||
game.input(inp);
|
||||
Event::Input(inp) => {
|
||||
let ev = Event::Input(inp);
|
||||
game.input(&ev);
|
||||
}
|
||||
_ => {
|
||||
|
||||
|
|
Loading…
Reference in New Issue