coalesce controls

This commit is contained in:
Donald Ball 2025-11-14 21:35:05 -05:00
parent 9f78b280cd
commit 89c3b42db2

View file

@ -9,7 +9,7 @@ local function initGame()
bullet = { bullet = {
timerLimit = 0.5, timerLimit = 0.5,
radius = 5, radius = 5,
} },
}, },
asteroids = { asteroids = {
stages = { stages = {
@ -19,6 +19,12 @@ local function initGame()
{ speed = 20, radius = 80 }, { speed = 20, radius = 80 },
}, },
}, },
controls = {
ship = {
turnRate = 10,
thrustRate = 100,
},
},
} }
end end
@ -72,19 +78,18 @@ function love.load()
end end
function love.update(dt) function love.update(dt)
local turnSpeed = 10
if love.keyboard.isDown('right') then if love.keyboard.isDown('right') then
state.ship.angle = state.ship.angle + turnSpeed * dt state.ship.angle = state.ship.angle + game.controls.ship.turnRate * dt
end end
if love.keyboard.isDown('left') then if love.keyboard.isDown('left') then
state.ship.angle = state.ship.angle - turnSpeed * dt state.ship.angle = state.ship.angle - game.controls.ship.turnRate * dt
end end
state.ship.angle = state.ship.angle % (2 * math.pi) state.ship.angle = state.ship.angle % (2 * math.pi)
if love.keyboard.isDown('up') then if love.keyboard.isDown('up') then
local shipSpeed = 100 local shipSpeed = 100
state.ship.speed.x = state.ship.speed.x + math.cos(state.ship.angle) * shipSpeed * dt state.ship.speed.x = state.ship.speed.x + math.cos(state.ship.angle) * game.controls.ship.thrustRate * dt
state.ship.speed.y = state.ship.speed.y + math.sin(state.ship.angle) * shipSpeed * dt state.ship.speed.y = state.ship.speed.y + math.sin(state.ship.angle) * game.controls.ship.thrustRate * dt
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