diff --git a/src/Marble.hx b/src/Marble.hx index fcb6c87a..a9f0cfb9 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -2147,6 +2147,25 @@ class Marble extends GameObject { move.d = new Vector(); move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis); move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis); + + if (Settings.controlsSettings.moddedController) { + // we need to scale the moves to square instead of circle + var moveLen = Math.sqrt(move.d.x * move.d.x + move.d.y * move.d.y); + if (moveLen > 0.00001) { + // Normalize the vector + var normalizedX = move.d.x / moveLen; + var normalizedY = move.d.y / moveLen; + + // Scale to square - this allows diagonal movements to reach the corners + var scaleFactor = Math.max(Math.abs(normalizedX), Math.abs(normalizedY)); + if (scaleFactor > 0) { + // Apply square mapping while preserving the original magnitude + move.d.x = normalizedX / scaleFactor * moveLen; + move.d.y = normalizedY / scaleFactor * moveLen; + } + } + } + if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) { if (Key.isDown(Settings.controlsSettings.forward)) { move.d.x -= 1; diff --git a/src/Settings.hx b/src/Settings.hx index 3eae6d44..5859ad6a 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -73,6 +73,7 @@ typedef ControlsSettings = { var rewind:Int; var chat:Int; var oobRespawnKeyByPowerup:Bool; + var moddedController:Bool; } typedef TouchSettings = { @@ -166,7 +167,8 @@ class Settings { blast: Key.MOUSE_RIGHT, rewind: Key.R, chat: Key.T, - oobRespawnKeyByPowerup: false + oobRespawnKeyByPowerup: false, + moddedController: false }; public static var touchSettings:TouchSettings = { @@ -473,6 +475,9 @@ class Settings { if (controlsSettings.oobRespawnKeyByPowerup == null) { controlsSettings.oobRespawnKeyByPowerup = false; } + if (controlsSettings.moddedController == null) { + controlsSettings.moddedController = false; + } if (optionsSettings.rewindEnabled == null) { optionsSettings.rewindEnabled = false; } diff --git a/src/gui/MiscOptionsGui.hx b/src/gui/MiscOptionsGui.hx index 1941cfa6..a5a7bbc0 100644 --- a/src/gui/MiscOptionsGui.hx +++ b/src/gui/MiscOptionsGui.hx @@ -102,6 +102,12 @@ class MiscOptionsGui extends GuiImage { }, 0.5, 118); oobResOpt.setCurrentOption(Settings.controlsSettings.oobRespawnKeyByPowerup ? 1 : 0); + var moddedOpt = optionCollection.addOption(1, "Emulate Modded Controller", ["No", "Yes"], (idx) -> { + Settings.controlsSettings.moddedController = (idx == 1); + return true; + }, 0.5, 118); + moddedOpt.setCurrentOption(Settings.controlsSettings.moddedController ? 1 : 0); + var bottomBar = new GuiControl(); bottomBar.position = new Vector(0, 590); bottomBar.extent = new Vector(640, 200); diff --git a/src/net/MoveManager.hx b/src/net/MoveManager.hx index 0ec06c2c..e381e594 100644 --- a/src/net/MoveManager.hx +++ b/src/net/MoveManager.hx @@ -76,6 +76,25 @@ class MoveManager { if (!MarbleGame.instance.paused) { move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis); move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis); + + if (Settings.controlsSettings.moddedController) { + // we need to scale the moves to square instead of circle + var moveLen = Math.sqrt(move.d.x * move.d.x + move.d.y * move.d.y); + if (moveLen > 0.00001) { + // Normalize the vector + var normalizedX = move.d.x / moveLen; + var normalizedY = move.d.y / moveLen; + + // Scale to square - this allows diagonal movements to reach the corners + var scaleFactor = Math.max(Math.abs(normalizedX), Math.abs(normalizedY)); + if (scaleFactor > 0) { + // Apply square mapping while preserving the original magnitude + move.d.x = normalizedX / scaleFactor * moveLen; + move.d.y = normalizedY / scaleFactor * moveLen; + } + } + } + if (@:privateAccess !MarbleGame.instance.world.playGui.isChatFocused()) { if (Key.isDown(Settings.controlsSettings.forward)) { move.d.x -= 1; @@ -89,6 +108,8 @@ class MoveManager { if (Key.isDown(Settings.controlsSettings.right)) { move.d.y -= 1; } + move.d.x = Util.clamp(move.d.x, -1, 1); + move.d.y = Util.clamp(move.d.y, -1, 1); if (Key.isDown(Settings.controlsSettings.jump) || MarbleGame.instance.touchInput.jumpButton.pressed || Gamepad.isDown(Settings.gamepadSettings.jump)) {