add throttle

This commit is contained in:
Donald Ball 2025-11-20 21:42:14 -05:00
parent 38af0bcaa1
commit e2fe2499d4
2 changed files with 6 additions and 4 deletions

View file

@ -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

View file

@ -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