utils: Moved joystick direction retrieval code to utils

This commit is contained in:
Erkki Seppälä 2014-10-26 12:32:22 +02:00
parent 704b9815ac
commit c11ad05175
2 changed files with 20 additions and 3 deletions

View file

@ -138,9 +138,7 @@ function level_state:update(dt)
return value return value
end end
local rotation = getAxis(AXISMAP[player].rotation[1]) + getAxis(AXISMAP[player].rotation[2]) players[player]:joystick(getRotation(j, player), getThrottle(j, player))
local throttle = getAxis(AXISMAP[player].throttle[1]) + getAxis(AXISMAP[player].throttle[2])
players[player]:joystick(rotation, throttle)
end end
end end

View file

@ -102,3 +102,22 @@ function getJoystickButtons(j)
end end
return buttons return buttons
end 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