add engine burn
This commit is contained in:
parent
e2fe2499d4
commit
7eee00d7ea
3 changed files with 21 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ local function initGame()
|
|||
},
|
||||
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
|
||||
maxThrust = 200,
|
||||
engineSound = love.sound.newSoundData('resources/enginehum3.ogg'),
|
||||
},
|
||||
asteroids = {
|
||||
stages = {
|
||||
|
|
@ -78,6 +79,12 @@ end
|
|||
local state = {}
|
||||
|
||||
local function reset()
|
||||
if state.ship then
|
||||
state.ship.engineSound:stop()
|
||||
for _, bullet in ipairs(state.bullets) do
|
||||
bullet.sound:stop()
|
||||
end
|
||||
end
|
||||
state = initState()
|
||||
end
|
||||
|
||||
|
|
@ -98,6 +105,17 @@ function love.update(dt)
|
|||
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 })
|
||||
if not state.ship.engineSound:isPlaying() then
|
||||
state.ship.engineSound:play()
|
||||
end
|
||||
end
|
||||
state.ship.engineSound:setVolume(state.ship.throttle * 0.5)
|
||||
-- TODO which is better, keeping the sound playing looping at 0 or checking the
|
||||
-- state each update?
|
||||
if state.ship.throttle == 0 then
|
||||
if state.ship.engineSound:isPlaying() then
|
||||
state.ship.engineSound:stop()
|
||||
end
|
||||
end
|
||||
|
||||
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue