From cc04f14a3dd5bf2d35bcd2427931f0507311ba1e Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Sat, 26 Oct 2019 22:03:12 -0700 Subject: [PATCH] Controls should not be mutable (#24) --- examples/invaders/main.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/invaders/main.rs b/examples/invaders/main.rs index 79a28ab..0340de4 100644 --- a/examples/invaders/main.rs +++ b/examples/invaders/main.rs @@ -45,7 +45,6 @@ fn main() -> Result<(), Error> { let mut pixels = Pixels::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32, surface_texture)?; let mut invaders = World::new(debug); let mut time = Instant::now(); - let mut controls = Controls::default(); event_loop.run(move |event, _, control_flow| { // The one and only event that winit_input_helper doesn't have for us... @@ -68,14 +67,16 @@ fn main() -> Result<(), Error> { } // Keyboard controls - controls.direction = if input.key_held(VirtualKeyCode::Left) { - Direction::Left - } else if input.key_held(VirtualKeyCode::Right) { - Direction::Right - } else { - Direction::Still + let controls = Controls { + direction: if input.key_held(VirtualKeyCode::Left) { + Direction::Left + } else if input.key_held(VirtualKeyCode::Right) { + Direction::Right + } else { + Direction::Still + }, + fire: input.key_pressed(VirtualKeyCode::Space), }; - controls.fire = input.key_pressed(VirtualKeyCode::Space); // Adjust high DPI factor if let Some(factor) = input.hidpi_changed() {