-
Notifications
You must be signed in to change notification settings - Fork 1
/
soundmanager.hpp
58 lines (41 loc) · 1.04 KB
/
soundmanager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <map>
#include <string>
#include <SFML/Audio.hpp>
const std::string SOUNDS_DIR = "assets/sounds/";
class SoundManager
{
public:
enum Sound {
NONE,
// music:
MENU,
LEVEL,
// effects:
LEVEL_COMPLETED,
GAME_OVER
};
private:
sf::SoundBuffer menuSB;
sf::SoundBuffer levelSB;
sf::SoundBuffer levelCompletedSB;
sf::SoundBuffer gameOverSB;
std::map<Sound, sf::Sound> sounds = {
{ MENU, sf::Sound(menuSB) },
{ LEVEL, sf::Sound(levelSB) },
{ LEVEL_COMPLETED, sf::Sound(levelCompletedSB) },
{ GAME_OVER, sf::Sound(gameOverSB) }
};
Sound effectPlaying = NONE;
Sound musicPlaying = NONE;
static SoundManager *instance;
void lowerMusicVolume(bool lower = true);
SoundManager();
public:
static SoundManager& getInstance();
// https://github.com/SFML/SFML/issues/970
static void destroyInstance();
void changeMusic(Sound music);
void playEffect(Sound effect);
void update();
};