6. Sound
Select the sounds folder, in Resources, and drag tiro.wav, explosao.wav and dano.wav from the zip. The ▶ next to each sound plays the file.
Shot and damage
Section titled “Shot and damage”On Player, one line after spawn and another in hurt, after taking the life:
spawn("Bullet", self.x, self.y - 8, "Tiros") Audio.play("tiro", { volume = 0.4 }) -- ... game.lives = game.lives - 1 Audio.play("dano") spawn<Bullet>(x, y - 8.0f, "Tiros"); Audio::play("tiro", {.volume = 0.4f}); // ... --state().lives; Audio::play("dano");Explosion
Section titled “Explosion”On Enemy, in kill:
game.score = game.score + self.pontos Audio.play("explosao", { volume = 0.5 }) self:destroy() state().score += pontos; Audio::play("explosao", {.volume = 0.5f}); destroy();The sound name is the file name, without the extension. volume goes from 0 to 1. Background music: playMusic, in Sound.
Next part: 7. Game over
