40 lines
981 B
C++
40 lines
981 B
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <array>
|
|
#include <string>
|
|
|
|
#include <SFML/Audio.hpp>
|
|
|
|
enum SOUND_TYPE {
|
|
FOOTSTEP_SOUND = 0,
|
|
|
|
N_SOUNDS
|
|
};
|
|
|
|
class Audio
|
|
{
|
|
private:
|
|
// Struct for small sounds, like shots, foot steps, etc.
|
|
// As we always need to store SoundBuffer in the same scope as Sound, it's better to make struct.
|
|
struct SoundEffect {
|
|
sf::SoundBuffer buffer;
|
|
sf::Sound sound;
|
|
};
|
|
|
|
std::array<std::unique_ptr<SoundEffect>, N_SOUNDS> array_sounds;
|
|
std::unique_ptr<sf::Music> background_music;
|
|
|
|
public:
|
|
Audio(const std::string &background_file_name, std::array<std::string, N_SOUNDS> &&sounds_paths);
|
|
|
|
bool setSound(const SOUND_TYPE &type, const std::string &sound_file_path);
|
|
void playSound(const SOUND_TYPE &type);
|
|
|
|
bool setBackground(const std::string &music_file_path);
|
|
void playBackground();
|
|
void stopBackground();
|
|
void pauseBackground();
|
|
void setBackgroundVolume(const float &volume);
|
|
};
|