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