Adding sound effects

Now that we have the game's main music, let's add some sounds effects to the mix! We've covered sf::Sound,sf::SoundBuffer, and how to play sounds, so we're ready to jump right in.

We're going to have a few sound effects in our game. One for the death of an enemy, one for us being hit, one for each pickup, and one for the sound of torches that we'll be playing with later.

We'll start by defining the sf::Sound variables for each sound in Game.h:

/** * Torch sound. */ sf::Sound m_fireSound; /** * Gem pickup sound. */ sf::Sound m_gemPickupSound; /** * Coin pickup sound. */ sf::Sound m_coinPickupSound; /** * Key collect sound. */ sf::Sound m_keyPickupSound; /** * Enemy die sound. */ sf::Sound m_enemyDieSound; /** * Player hit sound. ...

Get Procedural Content Generation for C++ Game Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.