SHOW:
|
|
- or go back to the newest paste.
1 | - | /* sound -- sound handling. |
1 | + | |
2 | - | * Copyright (C) 2010-2011 The Zatacka X development team |
2 | + | |
3 | static Mix_Music *bgm = NULL; | |
4 | - | * This program is free software: you can redistribute it and/or modify |
4 | + | |
5 | - | * it under the terms of the GNU General Public License as published by |
5 | + | |
6 | - | * the Free Software Foundation, either version 3 of the License, or |
6 | + | |
7 | - | * (at your option) any later version. |
7 | + | |
8 | static Mix_Chunk *seBeeeeep = NULL; | |
9 | - | * This program is distributed in the hope that it will be useful, |
9 | + | |
10 | - | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | + | |
11 | - | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | + | |
12 | - | * GNU General Public License for more details. |
12 | + | |
13 | static Mix_Chunk *seCrash = NULL; | |
14 | - | * You should have received a copy of the GNU General Public License |
14 | + | |
15 | - | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | + | |
16 | static Mix_Chunk *seConfusion = NULL; | |
17 | static Mix_Chunk *seSharpturn = NULL; | |
18 | static Mix_Chunk *seTimestep = NULL; | |
19 | static Mix_Chunk *seMole = NULL; | |
20 | static Mix_Chunk *seWarp = NULL; | |
21 | static Mix_Chunk *seGhost = NULL; | |
22 | static Mix_Chunk *seDisable = NULL; | |
23 | static Mix_Chunk *seSwitch = NULL; | |
24 | static Mix_Chunk *sounds[N_SOUNDS]; | |
25 | ||
26 | /** | |
27 | * Initializes the mixer and loads sound files. | |
28 | * | |
29 | * @return -1 on failiure, 0 else. | |
30 | */ | |
31 | int initSound(void) | |
32 | { | |
33 | if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY * 2, MIX_DEFAULT_FORMAT, | |
34 | 2, 512) == -1 ) | |
35 | { | |
36 | return -1; | |
37 | } | |
38 | ||
39 | if ((bgm = Mix_LoadMUS("data/sound/theme1.ogg")) == NULL) { | |
40 | fileNotFound("data/sound/theme1.ogg"); | |
41 | return -1; | |
42 | } | |
43 | ||
44 | - | * Loads a sound effect into appropriate sound array index. |
44 | + | |
45 | return -1; | |
46 | - | * @param sound Pointer to where to put the loaded sound. |
46 | + | |
47 | - | * @param soundstr Name of the sound (.ogg added). |
47 | + | |
48 | - | * @param index Index in the sound array (0 --> N_SOUNDS). |
48 | + | |
49 | return -1; | |
50 | if (loadSound(seBeeeep, "beeeep", SOUND_BEEEEP) == -1) | |
51 | - | int loadSound(Mix_Chunk *sound, char *soundstr, int index) |
51 | + | |
52 | if (loadSound(seBeeeeep, "beeeeep", SOUND_BEEEEEP) == -1) | |
53 | - | char *soundpath = malloc(STRBUF); |
53 | + | |
54 | - | snprintf(soundpath, STRBUF, "data/sound/%s.ogg", soundstr); |
54 | + | |
55 | - | if ((sound = Mix_LoadWAV(soundpath)) == NULL) { |
55 | + | |
56 | - | fileNotFound(soundpath); |
56 | + | |
57 | - | free(soundpath); |
57 | + | |
58 | if (loadSound(seBeeeeeeeep, "beeeeeeeep", SOUND_BEEEEEEEEP) == -1) | |
59 | - | } else { |
59 | + | |
60 | - | sounds[index] = sound; |
60 | + | |
61 | - | free(soundpath); |
61 | + | |
62 | - | return 0; |
62 | + | |
63 | return -1; | |
64 | - | } |
64 | + | |
65 | return -1; | |
66 | if (loadSound(seFreeze, "freeze", SOUND_FREEZE) == -1) | |
67 | return -1; | |
68 | if (loadSound(seConfusion, "confusion", SOUND_CONFUSION) == -1) | |
69 | return -1; | |
70 | if (loadSound(seSharpturn, "sharpturn", SOUND_SHARPTURN) == -1) | |
71 | return -1; | |
72 | if (loadSound(seTimestep, "timestep", SOUND_TIMESTEP) == -1) | |
73 | return -1; | |
74 | if (loadSound(seMole, "mole", SOUND_MOLE) == -1) | |
75 | return -1; | |
76 | if (loadSound(seWarp, "warp", SOUND_WARP) == -1) | |
77 | return -1; | |
78 | if (loadSound(seGhost, "ghost", SOUND_GHOST) == -1) | |
79 | return -1; | |
80 | if (loadSound(seDisable, "ghost", SOUND_DISABLE) == -1) | |
81 | return -1; | |
82 | if (loadSound(seSwitch, "switch", SOUND_SWITCH) == -1) | |
83 | return -1; | |
84 | ||
85 | return 0; | |
86 | } |