-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoundPlayer.cpp
More file actions
64 lines (56 loc) · 1.32 KB
/
SoundPlayer.cpp
File metadata and controls
64 lines (56 loc) · 1.32 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
#include <iostream>
#include "SoundPlayer.h"
SoundPlayer::SoundPlayer()
{
int sdlret = SDL_Init(SDL_INIT_AUDIO);
if(sdlret == -1){
std::cout << "SDL value: " << sdlret << std::endl;
std::cout << SDL_GetError();
}
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
/*bgMusic = Mix_LoadMUS("sounds/bgMusic.wav");
if(bgMusic == NULL) {
std::cout << Mix_GetError() << std::endl;
}*/
//Mix_PlayMusic(bgMusic, -1);
Mix_AllocateChannels(24);
paddleSwing = Mix_LoadWAV("sounds/paddleSwing.wav");
score = Mix_LoadWAV("sounds/score.wav");
shipHit = Mix_LoadWAV("sounds/shipHit.wav");
mute = false;
}
void SoundPlayer::startBgMusic()
{
/*if (Mix_PlayingMusic() == 0) {
int err = Mix_PlayMusic(bgMusic, -1);
if (err == -1){
std::cout << SDL_GetError() << std::endl;
}
} else if (Mix_PausedMusic() == 1) {
Mix_ResumeMusic();
} else {
Mix_PauseMusic();
}*/
}
void SoundPlayer::playPaddleSwing()
{
if (Mix_Playing(1) == 0 && !mute){
Mix_PlayChannel(1, paddleSwing, 0);
}
}
void SoundPlayer::playScore()
{
if (Mix_Playing(2) == 0 && !mute)
Mix_PlayChannel(2, score, 0);
}
void SoundPlayer::playShipHit()
{
if (Mix_Playing(3) == 0 && !mute)
Mix_PlayChannel(3, shipHit, 0);
}
void SoundPlayer::soundOn(){
mute = false;
}
void SoundPlayer::soundOff(){
mute = true;
}