-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Fx.cpp
102 lines (67 loc) · 2.71 KB
/
Fx.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
91
92
93
94
95
96
97
98
99
100
101
102
/*
* QtSssSNibblers: SwissalpS Nibbles written with Qt-Framework
* Copyright (C) 2018-2019 Luke J. Zimmermann aka SwissalpS <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Fx.h"
#include "AppSettings.h"
namespace SwissalpS { namespace QtNibblers {
QHash<const Fx::Sounds, QSoundEffect*> Fx::aoSounds;
Fx::Fx(QObject *pParent) :
QObject(pParent) {
} // construct
Fx::~Fx() {
} // dealloc
// static
void Fx::play(const Sounds eSound) {
#ifdef QT_MULTIMEDIA_LIB
static AppSettings *pAS = AppSettings::pAppSettings();
// don't bother if muted
if (!pAS->get(AppSettings::sSettingGameSound).toBool()) return;
// // works too, but complicated. must first copy files then make playlist.....
// QMediaPlayer *pMP = new QMediaPlayer();
// pMP->setMedia(QMediaContent(QUrl::fromLocalFile("/home/luke/gitSwissalpS/QtSssSNibblers/Sounds/appear.ogg")));
// pMP->play();
// QSoundEffect can't read .ogg files so I had to convert them to .wav
// I made the teleporter sound less aggresive while I was at it.
// plus QMediaPlayer is too 'eeh' for this simple task
if (!Fx::aoSounds.contains(eSound)) {
QSoundEffect *pSound = new QSoundEffect();
switch (eSound) {
case Appear: pSound->setSource(QUrl::fromLocalFile(":/Sounds/appear.wav"));
break;
case Bonus: pSound->setSource(QUrl::fromLocalFile(":/Sounds/bonus.wav"));
break;
case Crash: pSound->setSource(QUrl::fromLocalFile(":/Sounds/crash.wav"));
break;
case GameOver: pSound->setSource(QUrl::fromLocalFile(":/Sounds/gameover.wav"));
break;
case Gobble: pSound->setSource(QUrl::fromLocalFile(":/Sounds/gobble.wav"));
break;
case Life: pSound->setSource(QUrl::fromLocalFile(":/Sounds/life.wav"));
break;
case Reverse: pSound->setSource(QUrl::fromLocalFile(":/Sounds/reverse.wav"));
break;
case Teleport: pSound->setSource(QUrl::fromLocalFile(":/Sounds/teleport.wav"));
break;
case None:
break;
} // switch eSound
Fx::aoSounds.insert(eSound, pSound);
} // if first request for this sound
Fx::aoSounds.value(eSound)->play();
#endif
} // play
} } // namespace SwissalpS::QtNibblers