use crate::util; #[derive(Debug)] pub struct Input { pub right: f32, pub up: f32, } impl Input { pub fn new() -> Input { Input { right: 0.0, up: 0.0, } } pub fn handle_down(&mut self, kc: winit::VirtualKeyCode) { match kc { winit::VirtualKeyCode::W => self.up -= 1.0, winit::VirtualKeyCode::A => self.right -= 1.0, winit::VirtualKeyCode::S => self.up += 1.0, winit::VirtualKeyCode::D => self.right += 1.0, _ => (), } self.up = util::clamp(self.up, -1.0, 1.0); self.right = util::clamp(self.right, -1.0, 1.0); } pub fn handle_up(&mut self, kc: winit::VirtualKeyCode) { match kc { winit::VirtualKeyCode::W => self.up += 1.0, winit::VirtualKeyCode::A => self.right += 1.0, winit::VirtualKeyCode::S => self.up -= 1.0, winit::VirtualKeyCode::D => self.right -= 1.0, _ => (), } self.up = util::clamp(self.up, -1.0, 1.0); self.right = util::clamp(self.right, -1.0, 1.0); } }