Let's add some audio to the game to make it a little more interesting. This will also provide audio feedback to the player to tell them whether the rocket was fired or an enemy was hit.
SFML supports .wav or .ogg files, but it doesn't support .mp3 files. For this project, all the files will be in the .ogg file format as it is good for compression and is also cross-platform compatible. To start, place the audio files in the Audio directory in the Assets folder of the system. With the audio files in place, we can start playing the audio files.
Audio files can be of two types:
- The background music, which is of a longer duration and a much higher quality than other files in the game. These files are played using the sf::Music class.
- Other sound files, such as sound effects – which are smaller in size and sometimes of lower quality – are played...