utils: Moved joystick direction retrieval code to utils
This commit is contained in:
parent
704b9815ac
commit
c11ad05175
2 changed files with 20 additions and 3 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
19
utils.lua
19
utils.lua
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue