gamepad turn
This commit is contained in:
parent
6c1338e3c2
commit
18062e9ca1
1 changed files with 3 additions and 8 deletions
|
|
@ -86,18 +86,13 @@ function love.load()
|
|||
end
|
||||
|
||||
function love.update(dt)
|
||||
if love.keyboard.isDown('right') then
|
||||
state.ship.angle = state.ship.angle + game.controls.ship.turnRate * dt
|
||||
end
|
||||
if love.keyboard.isDown('left') then
|
||||
state.ship.angle = state.ship.angle - game.controls.ship.turnRate * dt
|
||||
end
|
||||
state.ship.angle = state.ship.angle % (2 * math.pi)
|
||||
|
||||
if state.controls.joystick ~= nil then
|
||||
local thrust = state.controls.joystick:getGamepadAxis('triggerright') * game.controls.ship.maxThrust
|
||||
state.ship.speed.x = state.ship.speed.x + math.cos(state.ship.angle) * thrust * dt
|
||||
state.ship.speed.y = state.ship.speed.y + math.sin(state.ship.angle) * thrust * dt
|
||||
|
||||
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
||||
state.ship.angle = (state.ship.angle + spin * dt) % (2 * math.pi)
|
||||
end
|
||||
state.ship.x = (state.ship.x + state.ship.speed.x * dt) % game.width
|
||||
state.ship.y = (state.ship.y + state.ship.speed.y * dt) % game.height
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue