-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMonsterSound.cpp
More file actions
79 lines (70 loc) · 1.82 KB
/
Copy pathMonsterSound.cpp
File metadata and controls
79 lines (70 loc) · 1.82 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
#include "MonsterSound.h"
#include <iostream>
MonsterSound::MonsterSound() {
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
//Initialize SDL_mixer
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
if (!loadMedia())
{
printf( "Failed to load media!\n");
}
}
MonsterSound::~MonsterSound() {
closeMedia();
}
bool MonsterSound::loadMedia()
{
//Load music
aggro_sound = Mix_LoadWAV( "found.wav" );
if( aggro_sound == NULL )
{
cout << Mix_GetError();
printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
death_sound = Mix_LoadWAV( "dead_monster.wav" );
if( death_sound == NULL )
{
cout << Mix_GetError();
printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
life_up = Mix_LoadWAV( "life_up.wav" );
if( life_up == NULL )
{
cout << Mix_GetError();
printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
return success;
}
void MonsterSound::monster_aggro()
{
Mix_PlayChannel( -1, aggro_sound, 0 );
}
void MonsterSound::death(int monsters_killed)
{
if (monsters_killed%10 == 0)
Mix_PlayChannel( -1, life_up, 0);
else
Mix_PlayChannel( -1, death_sound, 0 );
}
void MonsterSound::closeMedia()
{
Mix_FreeChunk( aggro_sound );
aggro_sound = NULL;
Mix_FreeChunk( death_sound );
death_sound = NULL;
//Quit SDL subsystems
Mix_Quit();
SDL_Quit();
}