Controls should not be mutable (#24)

This commit is contained in:
Jay Oster 2019-10-26 22:03:12 -07:00 committed by GitHub
parent 31225385c7
commit cc04f14a3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 pixels = Pixels::new(SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32, surface_texture)?;
let mut invaders = World::new(debug); let mut invaders = World::new(debug);
let mut time = Instant::now(); let mut time = Instant::now();
let mut controls = Controls::default();
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
// The one and only event that winit_input_helper doesn't have for us... // The one and only event that winit_input_helper doesn't have for us...
@ -68,14 +67,16 @@ fn main() -> Result<(), Error> {
} }
// Keyboard controls // Keyboard controls
controls.direction = if input.key_held(VirtualKeyCode::Left) { let controls = Controls {
Direction::Left direction: if input.key_held(VirtualKeyCode::Left) {
} else if input.key_held(VirtualKeyCode::Right) { Direction::Left
Direction::Right } else if input.key_held(VirtualKeyCode::Right) {
} else { Direction::Right
Direction::Still } else {
Direction::Still
},
fire: input.key_pressed(VirtualKeyCode::Space),
}; };
controls.fire = input.key_pressed(VirtualKeyCode::Space);
// Adjust high DPI factor // Adjust high DPI factor
if let Some(factor) = input.hidpi_changed() { if let Some(factor) = input.hidpi_changed() {