diff --git a/level_state.lua b/level_state.lua index 08d307c..098f9a9 100644 --- a/level_state.lua +++ b/level_state.lua @@ -138,9 +138,7 @@ function level_state:update(dt) return value end - local rotation = getAxis(AXISMAP[player].rotation[1]) + getAxis(AXISMAP[player].rotation[2]) - local throttle = getAxis(AXISMAP[player].throttle[1]) + getAxis(AXISMAP[player].throttle[2]) - players[player]:joystick(rotation, throttle) + players[player]:joystick(getRotation(j, player), getThrottle(j, player)) end end diff --git a/utils.lua b/utils.lua index bc16ddd..d7f65ee 100644 --- a/utils.lua +++ b/utils.lua @@ -102,3 +102,22 @@ function getJoystickButtons(j) end return buttons end + +function getJoystickAxis(joystick, info) + local value = 0 + if info.axis > 0 and joystick:getAxisCount() >= info.axis then + value = joystick:getAxis(info.axis) + if info.flipped then + value = -value + end + end + return value +end + +function getRotation(joystick, player) + return getJoystickAxis(joystick, AXISMAP[player].rotation[1]) + getJoystickAxis(joystick, AXISMAP[player].rotation[2]) +end + +function getThrottle(joystick, player) + return getJoystickAxis(joystick, AXISMAP[player].throttle[1]) + getJoystickAxis(joystick, AXISMAP[player].throttle[2]) +end