-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAudio.cpp
More file actions
91 lines (79 loc) · 1.21 KB
/
Copy pathAudio.cpp
File metadata and controls
91 lines (79 loc) · 1.21 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Audio.h"
#include <SFML\Audio.hpp>
Audio::Audio(bool load_everything, bool menu)
{
if (load_everything)
{
loadMusic(menu);
loadSounds();
}
}
Audio::~Audio()
{
this->music.stop();
for (size_t i = 0; i < COUNT; i++)
{
buffer[i].stop();
}
}
bool Audio::loadMusic(bool menu)
{
string path;
if (menu)
path = "Data/menu.ogg";
else
path = "Data/game.ogg";
if(!music.openFromFile(path))
return false;
music.setLoop(true);
music.setVolume(50);
return true;
}
bool Audio::loadSounds()
{
string name[COUNT] = {"pickup.wav", "game_over.wav", "level_over.wav", "level_completed.ogg"};
for (size_t i = 0; i < COUNT; i++)
{
if (!buffer[i].openFromFile("Data/" + name[i]))
{
buffer[i].setLoop(false);
return false;
}
}
return true;
}
void Audio::playMusic()
{
music.play();
}
void Audio::stopMusic()
{
music.stop();
}
void Audio::playSound(SoundType type)
{
buffer[type].play();
}
void Audio::stopSound(SoundType type)
{
buffer[type].stop();
}
void Audio::setVolume(bool mute)
{
if (mute)
{
music.stop();
for (size_t i = 0; i < COUNT; i++)
{
buffer[i].setVolume(0);
}
}
else
{
music.play();
for (size_t i = 0; i < COUNT; i++)
{
buffer[i].setVolume(100);
}
}
}