~comcloudway/little_town

14db88a6a76a62c0ec83515761bdca54af20e3f5 — Jakob Meier 1 year, 8 months ago deef995
Added mouse-wheel camera move gesture
1 files changed, 24 insertions(+), 4 deletions(-)

M src/screens/build.rs
M src/screens/build.rs => src/screens/build.rs +24 -4
@@ 63,7 63,8 @@ pub struct BuildScreen {
    grid: HashMap<Pos3, (Block, Direction)>,
    cam: Camera,
    show_inv: bool,
    inv: Inventory
    inv: Inventory,
    mouse_position: Option<(f32, f32)>
}
impl BuildScreen {
    pub fn new() -> Self {


@@ 80,7 81,8 @@ impl BuildScreen {
            grid: HashMap::new(),
            cam: Camera::new(),
            show_inv: false,
            inv: Inventory::new()
            inv: Inventory::new(),
            mouse_position: None
        };

        this.grid.insert(Pos3::new(0, 0, 0), (Block::default(), Direction::North));


@@ 396,10 398,10 @@ impl GameComponent for BuildScreen {

        // keyboard control
        if is_key_down(KeyCode::Down) {
            self.cam.center.y += 1.0 * (1.0/self.cam.scale);
            self.cam.center.y -= 1.0 * (1.0/self.cam.scale);
        }
        if is_key_down(KeyCode::Up) {
            self.cam.center.y -= 1.0 * (1.0/self.cam.scale);
            self.cam.center.y += 1.0 * (1.0/self.cam.scale);
        }
        if is_key_down(KeyCode::Left) {
            self.cam.center.x += 1.0 * (1.0/self.cam.scale);


@@ 407,6 409,24 @@ impl GameComponent for BuildScreen {
        if is_key_down(KeyCode::Right) {
            self.cam.center.x -= 1.0 * (1.0/self.cam.scale);
        }
        if is_key_down(KeyCode::C) {
            self.cam.center = CVec2::new(0.0, 0.0);
        }
        if is_mouse_button_down(MouseButton::Middle) {
            let (nx, ny) = mouse_position();
            if let Some((ox, oy)) = self.mouse_position {

                let dx = nx - ox;
                let dy = ny - oy;

                self.cam.center.x += dx;
                self.cam.center.y += dy;
            }
            self.mouse_position = Some((nx, ny));
        }
        if is_mouse_button_released(MouseButton::Middle) {
            self.mouse_position = None;
        }

        // change block direction
        if is_key_pressed(KeyCode::W) {