-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfx.cpp
128 lines (103 loc) · 2.96 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "fx.hpp"
#include <iostream>
using namespace std;
void FX::initialize() //to initialize the audio class
{ if (Mix_Init(MIX_INIT_OGG | MIX_INIT_MP3) != 0) {
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
}
}
}
void FX::load() //to load the music
{
jetpack = Mix_LoadWAV( "music/jetpack_plain_lp.wav" );
if( jetpack == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
coin = Mix_LoadWAV( "music/coin.wav" );
if( coin == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
zapped = Mix_LoadWAV( "music/zapper.wav" );
if( zapped == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
missile = Mix_LoadWAV( "music/missile_fire.wav" );
if( missile == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
laser_warmup = Mix_LoadWAV( "music/laser_warning.wav" );
if( laser_warmup == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
laser_fire = Mix_LoadWAV( "music/laser_fire_lp.wav" );
if( laser_fire == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
ball = Mix_LoadWAV( "music/balleffect2.wav" );
if( ball == NULL )
{
printf( "Failed to load scratch sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
}
}
void FX::destroy()
{
Mix_FreeChunk( jetpack);
Mix_FreeChunk( zapped);
Mix_FreeChunk( coin );
Mix_FreeChunk(missile);
Mix_FreeChunk( laser_fire );
Mix_FreeChunk(laser_warmup);
Mix_FreeChunk(ball);
jetpack = NULL;
zapped = NULL;
coin = NULL;
missile = NULL;
laser_fire=NULL;
laser_warmup=NULL;
ball = NULL;
// touch = NULL;
}
void FX::effect(char choice) //to play sounds on choice
{
if (choice == 'j')
{ Mix_VolumeChunk(jetpack, 32);
Mix_PlayChannel( -1, jetpack, 0 );
Mix_FadeOutChannel(1, 100);
}
if (choice == 'z')
{
Mix_PlayChannel( -1, zapped, 0 );
}
if (choice == 'c')
{ Mix_VolumeChunk(coin, 32);
Mix_PlayChannel( -1, coin, 0 );
// cout<<"Coin chime"<<endl;
}
if (choice == 'm')
{
Mix_PlayChannel( -1, missile, 0 );
}
if (choice == 'w')
{
Mix_VolumeChunk(laser_warmup,32);
Mix_PlayChannel( -1, laser_warmup, 0 );
}
if (choice == 'l')
{
Mix_VolumeChunk(laser_fire,32);
Mix_PlayChannel( -1, laser_fire, 0 );
}
if (choice == 'b'){
Mix_PlayChannel(-1,ball,0);
// cout<<"ball sound"<<endl;
Mix_VolumeChunk(ball,35);
}
}