Add panning with rmb
This commit is contained in:
parent
5dc1faad63
commit
46c288be8c
1 changed files with 19 additions and 0 deletions
19
src/main.rs
19
src/main.rs
|
@ -11,6 +11,7 @@ use sdl2::keyboard::Keycode;
|
|||
use sdl2::pixels::Color;
|
||||
use sdl2::render::WindowCanvas;
|
||||
use sdl2::image::INIT_PNG;
|
||||
use sdl2::mouse::MouseButton;
|
||||
|
||||
use perlin_noise::PerlinNoise;
|
||||
|
||||
|
@ -22,11 +23,16 @@ struct GameState {
|
|||
camera_x: i32,
|
||||
camera_y: i32,
|
||||
|
||||
camera_panning: bool,
|
||||
}
|
||||
|
||||
impl GameState {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
camera_x: 0,
|
||||
camera_y: 0,
|
||||
|
||||
camera_panning: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +64,19 @@ fn update(event_pump: &mut EventPump, game_state: &mut GameState) -> bool {
|
|||
};
|
||||
},
|
||||
|
||||
Event::MouseButtonDown { mouse_btn: MouseButton::Right, .. } => {
|
||||
game_state.camera_panning = true;
|
||||
},
|
||||
Event::MouseButtonUp { mouse_btn: MouseButton::Right, .. } => {
|
||||
game_state.camera_panning = false;
|
||||
},
|
||||
Event::MouseMotion { xrel: x, yrel: y, .. } => {
|
||||
if game_state.camera_panning {
|
||||
game_state.camera_x -= x;
|
||||
game_state.camera_y -= y;
|
||||
}
|
||||
}
|
||||
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue