-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.cpp
46 lines (36 loc) · 994 Bytes
/
sound.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
#include "sound.h"
static void loadSounds(void);
static Mix_Chunk* sounds[SND_MAX];
static Mix_Music* music;
void initSounds(void)
{
memset(sounds, 0, sizeof(Mix_Chunk*) * SND_MAX);
music = NULL;
loadSounds();
}
void loadMusic(const char *filename)
{
if (music != NULL)
{
Mix_HaltMusic();
Mix_FreeMusic(music);
music = NULL;
}
music = Mix_LoadMUS(filename);
}
void playMusic(int loop)
{
Mix_PlayMusic(music, (loop) ? -1 : 0);
}
void playSound(int id, int channel)
{
Mix_PlayChannel(channel, sounds[id], 0);
}
static void loadSounds(void)
{
sounds[SND_PLAYER_FIRE] = Mix_LoadWAV("sound/334227__jradcoolness__laser.ogg");
sounds[SND_ALIEN_FIRE] = Mix_LoadWAV("sound/196914__dpoggioli__laser-gun.ogg");
sounds[SND_PLAYER_DIE] = Mix_LoadWAV("sound/245372__quaker540__hq-explosion.ogg");
sounds[SND_ALIEN_DIE] = Mix_LoadWAV("sound/10 Guage Shotgun-SoundBible.com-74120584.ogg");
sounds[SND_POINTS] = Mix_LoadWAV("sound/mixkit-space-coin-win-notification-271.wav");
}