diff --git a/asteroids/main.lua b/asteroids/main.lua index b9fca5e..65bd3a4 100644 --- a/asteroids/main.lua +++ b/asteroids/main.lua @@ -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