From e2fe2499d47e9044cd9276a698975effb8f60a96 Mon Sep 17 00:00:00 2001 From: Donald Ball Date: Thu, 20 Nov 2025 21:42:14 -0500 Subject: [PATCH] add throttle --- asteroids/actors.lua | 1 + asteroids/main.lua | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/asteroids/actors.lua b/asteroids/actors.lua index 0720d4c..31f2cf4 100644 --- a/asteroids/actors.lua +++ b/asteroids/actors.lua @@ -83,6 +83,7 @@ function actors.buildActors(game) spin = 0, facing = phys.tau * 3 / 4, radius = game.ship.radius, + throttle = 0, } for k, v in pairs(game.ship) do instance[k] = v diff --git a/asteroids/main.lua b/asteroids/main.lua index 5b77da5..e45fcb5 100644 --- a/asteroids/main.lua +++ b/asteroids/main.lua @@ -17,6 +17,7 @@ local function initGame() sound = love.sound.newSoundData('resources/bullet.mp3'), }, sprite = love.graphics.newImage('resources/playerShip1_blue.png'), + maxThrust = 200, }, asteroids = { stages = { @@ -29,7 +30,6 @@ local function initGame() controls = { ship = { turnRate = 10, - maxThrust = 200, }, }, } @@ -94,9 +94,10 @@ end function love.update(dt) if state.controls.joystick ~= nil then - local thrust = state.controls.joystick:getGamepadAxis('triggerright') * game.controls.ship.maxThrust - if thrust > 0 then - phys.apply(state.ship, { speed = thrust * dt, angle = state.ship.facing }) + state.ship.throttle = state.controls.joystick:getGamepadAxis('triggerright') + if state.ship.throttle > 0 then + local speed = state.ship.throttle * state.ship.maxThrust * dt + phys.apply(state.ship, { speed = speed, angle = state.ship.facing }) end local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate