forked from Sicatriz/CppGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.cpp
91 lines (79 loc) · 2.2 KB
/
audio.cpp
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
#include "audio.h"
using namespace insemi;
// MUSIC AND OUTPUT INSTANCE
Audio::Audio(): QObject()
{
music = new QMediaPlayer();
audioOutput = new QAudioOutput();
}
// FIRE BULLET SOUND
void Audio::playBullet(float bulletVolume) const
{
music->setAudioOutput(audioOutput);
music->setSource(QUrl("qrc:/sounds/sounds/shoot1.wav"));
music->audioOutput()->setVolume(bulletVolume);
music->play();
}
// BULLET IMPACT SOUND
void Audio::playBulletHit(int volume) const
{
music->setAudioOutput(audioOutput);
music->setSource(QUrl("qrc:/sounds/sounds/Explosion.wav"));
music->audioOutput()->setVolume(volume);
music->play();
}
// SHIP COLLISION SOUND RANDOMISED
void Audio::playShipCollisionSound(float crashVolume)
{
int ran = rand()%5;
music->setAudioOutput(audioOutput);
if(ran%5 == 0)
{
music->setSource(QUrl("qrc:/sounds/sounds/adios.wav"));
}
else if(ran%5 == 1)
{
music->setSource(QUrl("qrc:/sounds/sounds/shouting_karen.wav"));
}
else if(ran%5 == 2)
{
music->setSource(QUrl("qrc:/sounds/sounds/cry_karen.wav"));
}
else if(ran%5 == 3)
{
music->setSource(QUrl("qrc:/sounds/sounds/death_1_ian.wav"));
}
else if(ran%5 == 4)
{
music->setSource(QUrl("qrc:/sounds/sounds/death_5_sean.wav"));
}
else
{
music->setSource(QUrl("qrc:/sounds/sounds/death_8_sean.wav"));
}
music->audioOutput()->setVolume(crashVolume);
music->play();
}
// BACKGROUND SOUND
void Audio::playBackgroundMusic(float backgroundVolume) const
{
music->setAudioOutput(audioOutput);
music->setSource(QUrl("qrc:/sounds/sounds/slow-travel.wav"));
audioOutput->setVolume(backgroundVolume);
music->play();
}
// GAME OVER
void Audio::playGameOver(int volume) const
{
music->setAudioOutput(audioOutput);
music->setSource(QUrl("qrc:/sounds/sounds/gameOver_karen.wav"));
music->audioOutput()->setVolume(volume);
music->play();
}
// BUFF PICKUP SOUND
void Audio::playBuffSound(int volume) const{
music->setAudioOutput(audioOutput);
music->setSource(QUrl("qrc:/sounds/sounds/buffPickup.wav"));
music->audioOutput()->setVolume(volume);
music->play();
}