Preparing sound effects
In this section, we will create all the SoundBuffer
and Sound
objects that we need to add a range of sound effects to the game.
Start by adding the required SFML #include
statements:
#include <sstream> #include <fstream> #include <SFML/Graphics.hpp> #include <SFML/Audio.hpp> #include "ZombieArena.h" #include "Player.h" #include "TextureHolder.h" #include "Bullet.h" #include "Pickup.h"
Now, go ahead and add the seven SoundBuffer
and Sound
objects that load and prepare the seven sound files that we prepared in Chapter 8, SFML Views – Starting the Zombie Shooter Game:
// When did we last update the HUD? int framesSinceLastHUDUpdate = 0; // What time was the last update Time timeSinceLastUpdate; // How often (in frames) should we update the HUD int fpsMeasurementFrameInterval = 1000; // Prepare the hit sound SoundBuffer hitBuffer; hitBuffer.loadFromFile("sound/hit.wav...