2022-11-04 16:44:26 +01:00
|
|
|
#pragma once
|
2020-03-19 22:59:21 +01:00
|
|
|
|
|
|
|
#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;
|
|
|
|
};
|
|
|
|
|
2022-11-04 16:44:26 +01:00
|
|
|
std::array<std::unique_ptr<SoundEffect>, N_SOUNDS> array_sounds;
|
|
|
|
std::unique_ptr<sf::Music> background_music;
|
2020-03-19 22:59:21 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
};
|