-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfxmanager.cpp
59 lines (42 loc) · 1.62 KB
/
sfxmanager.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
//
// Created by lunah on 4/17/2024.
//
#include "sfxmanager.h"
#include <iostream>
SFXManager::SFXManager() {
sounds = {
{Sounds::Explosion, new QSoundEffect()},
{Sounds::Firing, new QSoundEffect()},
{Sounds::PlayerTreads, new QSoundEffect()},
{Sounds::EnemyTreads, new QSoundEffect()},
{Sounds::Collision, new QSoundEffect}
};
sounds[Sounds::Explosion]->setSource(QUrl::fromLocalFile("./assets/sfx/explosion.wav"));
sounds[Sounds::Explosion]->setVolume(0.5f);
sounds[Sounds::Firing]->setSource(QUrl::fromLocalFile("./assets/sfx/tankFire.wav"));
sounds[Sounds::Firing]->setVolume(0.5f);
sounds[Sounds::PlayerTreads]->setSource(QUrl::fromLocalFile("./assets/sfx/tankTread.wav"));
sounds[Sounds::PlayerTreads]->setLoopCount(QSoundEffect::Infinite);
sounds[Sounds::PlayerTreads]->setVolume(1.0f);
sounds[Sounds::EnemyTreads]->setSource(QUrl::fromLocalFile("./assets/sfx/tankTread.wav"));
sounds[Sounds::EnemyTreads]->setLoopCount(QSoundEffect::Infinite);
sounds[Sounds::EnemyTreads]->setVolume(1.0f);
sounds[Sounds::Collision]->setSource(QUrl::fromLocalFile("./assets/sfx/collide.wav"));
sounds[Sounds::Collision]->setVolume(0.25f);
}
void SFXManager::playSound(SFXManager::Sounds sound) {
QSoundEffect* sfx = sounds.at(sound);
if (!sfx->isPlaying()) {
sfx->play();
}
}
void SFXManager::stopSound(SFXManager::Sounds sound) {
QSoundEffect* sfx = sounds.at(sound);
if (sfx->isPlaying()) {
sfx->stop();
}
}
SFXManager::~SFXManager() {
for(auto& pair : sounds) { delete pair.second; }
sounds.clear();
}