diff --git a/asteroids/main.lua b/asteroids/main.lua index b5d28ef..7e2d872 100644 --- a/asteroids/main.lua +++ b/asteroids/main.lua @@ -10,6 +10,7 @@ local function initGame() radius = 5, speed = 500, time = 4, + sound = love.sound.newSoundData('resources/bullet.mp3'), }, -- 99x75 sprite = love.graphics.newImage('resources/ship.png'), @@ -158,12 +159,15 @@ function love.gamepadpressed(joystick, button) end if button == "b" then -- debounce, perhaps - table.insert(state.bullets, { + local bullet = { x = state.ship.x + math.cos(state.ship.angle) * game.ship.radius, y = state.ship.y + math.sin(state.ship.angle) * game.ship.radius, angle = state.ship.angle, timeLeft = game.ship.bullet.time, - }) + sound = love.audio.newSource(game.ship.bullet.sound), + } + table.insert(state.bullets, bullet) + bullet.sound:play() end end diff --git a/asteroids/resources/bullet.mp3 b/asteroids/resources/bullet.mp3 new file mode 100644 index 0000000..d1f2ba2 Binary files /dev/null and b/asteroids/resources/bullet.mp3 differ