add engine burn
This commit is contained in:
parent
e2fe2499d4
commit
7eee00d7ea
3 changed files with 21 additions and 0 deletions
|
|
@ -91,6 +91,9 @@ function actors.buildActors(game)
|
||||||
for k, v in pairs(ship) do
|
for k, v in pairs(ship) do
|
||||||
instance[k] = v
|
instance[k] = v
|
||||||
end
|
end
|
||||||
|
instance.engineSound = love.audio.newSource(instance.engineSound)
|
||||||
|
instance.engineSound:setVolume(0)
|
||||||
|
instance.engineSound:setLooping(true)
|
||||||
setmetatable(instance, ships_mt)
|
setmetatable(instance, ships_mt)
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ local function initGame()
|
||||||
},
|
},
|
||||||
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
|
sprite = love.graphics.newImage('resources/playerShip1_blue.png'),
|
||||||
maxThrust = 200,
|
maxThrust = 200,
|
||||||
|
engineSound = love.sound.newSoundData('resources/enginehum3.ogg'),
|
||||||
},
|
},
|
||||||
asteroids = {
|
asteroids = {
|
||||||
stages = {
|
stages = {
|
||||||
|
|
@ -78,6 +79,12 @@ end
|
||||||
local state = {}
|
local state = {}
|
||||||
|
|
||||||
local function reset()
|
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()
|
state = initState()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -98,6 +105,17 @@ function love.update(dt)
|
||||||
if state.ship.throttle > 0 then
|
if state.ship.throttle > 0 then
|
||||||
local speed = state.ship.throttle * state.ship.maxThrust * dt
|
local speed = state.ship.throttle * state.ship.maxThrust * dt
|
||||||
phys.apply(state.ship, { speed = speed, angle = state.ship.facing })
|
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
|
end
|
||||||
|
|
||||||
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
local spin = state.controls.joystick:getGamepadAxis('leftx') * game.controls.ship.turnRate
|
||||||
|
|
|
||||||
BIN
asteroids/resources/enginehum3.ogg
Normal file
BIN
asteroids/resources/enginehum3.ogg
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue