gamepad turn

This commit is contained in:
Donald Ball 2025-11-15 16:29:07 -05:00
parent 6c1338e3c2
commit 18062e9ca1

View file

@ -86,18 +86,13 @@ function love.load()
end end
function love.update(dt) 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 if state.controls.joystick ~= nil then
local thrust = state.controls.joystick:getGamepadAxis('triggerright') * game.controls.ship.maxThrust 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.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 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 end
state.ship.x = (state.ship.x + state.ship.speed.x * dt) % game.width 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 state.ship.y = (state.ship.y + state.ship.speed.y * dt) % game.height