forked from WenlinMao/SleepWalking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioSystem.cpp
More file actions
137 lines (109 loc) · 3.28 KB
/
Copy pathAudioSystem.cpp
File metadata and controls
137 lines (109 loc) · 3.28 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "AudioSystem.hpp"
#include "Load.hpp"
#include "data_path.hpp"
Load < Sound::Sample > jump_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("jump.opus"));
});
Load < Sound::Sample > rotate_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("rotate.opus"));
});
Load < Sound::Sample > die_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("die.opus"));
});
Load < Sound::Sample > checkPoint_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("checkPoint.opus"));
});
Load < Sound::Sample > drag_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("drag.opus"));
});
Load < Sound::Sample > collect_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("collect.opus"));
});
Load < Sound::Sample > foot_steps_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("run.opus"));
});
Load < Sound::Sample > time_stop_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("timestop.opus"));
});
Load < Sound::Sample > bgm_sample(LoadTagDefault, []() -> Sound::Sample const* {
return new Sound::Sample(data_path("bgm.opus"));
});
AudioSystem::AudioSystem()
{
foot_steps_ps = Sound::loop_3D(*foot_steps_sample, 0.0f, glm::vec3(0));
time_stop_ps = Sound::loop_3D(*time_stop_sample, 0.0f, glm::vec3(0));
bgm_ps = Sound::loop_3D(*bgm_sample, 0.0f, glm::vec3(0));
}
AudioSystem::~AudioSystem()
{
Sound::stop_all_samples();
}
void AudioSystem::PlayShortAudio(const AudioSourceList sound, float volume /* = 1.0f */, const glm::vec3& pos /* = PlayerStats::Instance().player1Pos */)
{
switch (sound)
{
default:
break;
case AudioSourceList::Jump:
Sound::play_3D(*jump_sample, volume, pos);
break;
case AudioSourceList::Rotate:
Sound::play_3D(*rotate_sample, volume, pos);
break;
case AudioSourceList::Drag:
Sound::play_3D(*drag_sample, volume, pos);
break;
case AudioSourceList::Die:
Sound::play_3D(*die_sample, volume, pos);
break;
case AudioSourceList::CheckPoint:
Sound::play_3D(*checkPoint_sample, volume, pos);
break;
case AudioSourceList::Collect:
Sound::play_3D(*collect_sample, volume, pos);
break;
}
}
void AudioSystem::PlayLongAudio(const AudioSourceList sound, float volume /* = 1.0f */, const glm::vec3& pos /* = PlayerStats::Instance().player1Pos */)
{
switch (sound)
{
default:
break;
case AudioSourceList::Footsteps:
foot_steps_ps->set_position(pos);
foot_steps_ps->set_volume(volume);
break;
case AudioSourceList::Timestop:
time_stop_ps->set_position(pos);
time_stop_ps->set_volume(volume);
break;
case AudioSourceList::BGM:
bgm_ps->set_position(pos);
bgm_ps->set_volume(volume);
break;
}
}
void AudioSystem::StopLongAudio(const AudioSourceList sound)
{
switch (sound)
{
default:
break;
case AudioSourceList::Footsteps:
foot_steps_ps->set_volume(0.0f);
break;
case AudioSourceList::Timestop:
time_stop_ps->set_volume(0.0f);
break;
case AudioSourceList::BGM:
bgm_ps->set_volume(0.0f);
break;
}
}
void AudioSystem::StopAllAudio()
{
foot_steps_ps->set_volume(0.0f);
time_stop_ps->set_volume(0.0f);
bgm_ps->set_volume(0.0f);
}