From dcdec7f55f3cbba0c81a6fb60e6fd356293bf9f1 Mon Sep 17 00:00:00 2001 From: Joshua Fan Date: Mon, 11 Nov 2019 13:00:35 -0600 Subject: [PATCH] Add mouse-based movement (#1037) * Add mouse-based movement * Rename keybind to 'Follow Mouse' --- core/assets/bundles/bundle.properties | 1 + core/src/io/anuke/mindustry/entities/type/Player.java | 5 +++++ core/src/io/anuke/mindustry/input/Binding.java | 1 + 3 files changed, 7 insertions(+) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 49088f6dd2..c720bab5bf 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -660,6 +660,7 @@ keybind.press.axis = Press an axis or key... keybind.screenshot.name = Map Screenshot keybind.move_x.name = Move x keybind.move_y.name = Move y +keybind.mouse_move.name = Follow Mouse keybind.schematic_select.name = Select Region keybind.schematic_menu.name = Schematic Menu keybind.schematic_flip_x.name = Flip Schematic X diff --git a/core/src/io/anuke/mindustry/entities/type/Player.java b/core/src/io/anuke/mindustry/entities/type/Player.java index 7bb6cfdda2..186c8c8e3a 100644 --- a/core/src/io/anuke/mindustry/entities/type/Player.java +++ b/core/src/io/anuke/mindustry/entities/type/Player.java @@ -593,6 +593,11 @@ public class Player extends Unit implements BuilderMinerTrait, ShooterTrait{ movement.x += xa * speed; } + if(Core.input.keyDown(Binding.mouse_move)){ + movement.x += Mathf.clamp((Core.input.mouseX() - Core.graphics.getWidth() / 2) * 0.005f, -1, 1) * speed; + movement.y += Mathf.clamp((Core.input.mouseY() - Core.graphics.getHeight() / 2) * 0.005f, -1, 1) * speed; + } + Vector2 vec = Core.input.mouseWorld(control.input.getMouseX(), control.input.getMouseY()); pointerX = vec.x; pointerY = vec.y; diff --git a/core/src/io/anuke/mindustry/input/Binding.java b/core/src/io/anuke/mindustry/input/Binding.java index 8e5ca2bf64..918a878937 100644 --- a/core/src/io/anuke/mindustry/input/Binding.java +++ b/core/src/io/anuke/mindustry/input/Binding.java @@ -9,6 +9,7 @@ import io.anuke.arc.input.KeyCode; public enum Binding implements KeyBind{ move_x(new Axis(KeyCode.A, KeyCode.D), "general"), move_y(new Axis(KeyCode.S, KeyCode.W)), + mouse_move(KeyCode.MOUSE_BACK), select(KeyCode.MOUSE_LEFT), deselect(KeyCode.MOUSE_RIGHT), break_block(KeyCode.MOUSE_RIGHT),