diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-09-02 22:55:09 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-09-02 22:55:09 -0700 |
| commit | 8c2acf066fc9767a7011db056248ea657392f390 (patch) | |
| tree | b226b3c60cc0944752b299b277afe084bd260576 /src/input.rs | |
| parent | 51ecf9530dae94341e2ba96453a4bf7e376ad33b (diff) | |
refactor camera
Diffstat (limited to 'src/input.rs')
| -rw-r--r-- | src/input.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/input.rs b/src/input.rs index e795a61..108514e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -14,6 +14,8 @@ pub enum Input { Down, Right, + // camera + FreeCamera, CameraUp, CameraLeft, CameraDown, @@ -39,18 +41,19 @@ pub enum Input { Action6, } -const INPUT_VAR_LEN: usize = 21; +const INPUT_VAR_LEN: usize = 22; const KEYMAP: [(KeyCode, Input); INPUT_VAR_LEN] = [ (KeyCode::KeyW, Input::Up), (KeyCode::KeyA, Input::Left), (KeyCode::KeyS, Input::Down), (KeyCode::KeyD, Input::Right), + (KeyCode::KeyZ, Input::FreeCamera), (KeyCode::ArrowUp, Input::CameraUp), (KeyCode::ArrowLeft, Input::CameraLeft), (KeyCode::ArrowDown, Input::CameraDown), (KeyCode::ArrowRight, Input::CameraRight), - (KeyCode::Space, Input::Pause), + (KeyCode::KeyU, Input::Pause), (KeyCode::KeyX, Input::Step), (KeyCode::KeyC, Input::ClearGrid), (KeyCode::KeyV, Input::ClearEntities), @@ -108,14 +111,14 @@ impl InputManager { } } WindowEvent::CursorMoved { position, .. } => { - let (wp_x, wp_y) = - camera.screen_position_to_world(position.x as f32, position.y as f32); + let wp = camera + .screen_position_to_world(Vec2::new(position.x as f32, position.y as f32)); let ((cx, cy), (lx, ly)) = - CellManager::split_game_position(wp_x.round() as i32, wp_y.round() as i32); + CellManager::split_game_position(wp.x.round() as i32, wp.y.round() as i32); self.screen_mouse_pos = Vec2::new(position.x as f32, position.y as f32); - self.world_mouse_pos = Vec2::new(wp_x, wp_y); + self.world_mouse_pos = wp; self.chunk_mouse_pos = IVec2::new(cx, cy); self.local_mouse_pos = IVec2::new(lx as i32, ly as i32); } |
