add throttle
This commit is contained in:
parent
38af0bcaa1
commit
e2fe2499d4
2 changed files with 6 additions and 4 deletions
|
|
@ -83,6 +83,7 @@ function actors.buildActors(game)
|
||||||
spin = 0,
|
spin = 0,
|
||||||
facing = phys.tau * 3 / 4,
|
facing = phys.tau * 3 / 4,
|
||||||
radius = game.ship.radius,
|
radius = game.ship.radius,
|
||||||
|
throttle = 0,
|
||||||
}
|
}
|
||||||
for k, v in pairs(game.ship) do
|
for k, v in pairs(game.ship) do
|
||||||
instance[k] = v
|
instance[k] = v
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ local function initGame()
|
||||||
sound = love.sound.newSoundData('resources/bullet.mp3'),
|
sound = love.sound.newSoundData('resources/bullet.mp3'),
|
||||||
},
|
},
|
||||||
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
|
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
|
||||||
|
maxThrust = 200,
|
||||||
},
|
},
|
||||||
asteroids = {
|
asteroids = {
|
||||||
stages = {
|
stages = {
|
||||||
|
|
@ -29,7 +30,6 @@ local function initGame()
|
||||||
controls = {
|
controls = {
|
||||||
ship = {
|
ship = {
|
||||||
turnRate = 10,
|
turnRate = 10,
|
||||||
maxThrust = 200,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -94,9 +94,10 @@ end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
if state.controls.joystick ~= nil then
|
if state.controls.joystick ~= nil then
|
||||||
local thrust = state.controls.joystick:getGamepadAxis('triggerright') * game.controls.ship.maxThrust
|
state.ship.throttle = state.controls.joystick:getGamepadAxis('triggerright')
|
||||||
if thrust > 0 then
|
if state.ship.throttle > 0 then
|
||||||
phys.apply(state.ship, { speed = thrust * dt, angle = state.ship.facing })
|
local speed = state.ship.throttle * state.ship.maxThrust * dt
|
||||||
|
phys.apply(state.ship, { speed = speed, angle = state.ship.facing })
|
||||||
end
|
end
|
||||||
|
|
||||||
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue