4 // Copyright 2007, 2008 Lancer-X/ASCEAI
6 // This file is part of Meritous Recharged.
8 // Meritous Recharged is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
13 // Meritous Recharged is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with Meritous Recharged. If not, see <http://www.gnu.org/licenses/>.
26 #include <SDL_image.h>
27 #include <SDL_mixer.h>
30 #include "levelblit.h"
34 char *tracks
[13] = {"dat/m/ICEFRONT.S3M",
39 "dat/m/iller_knarkloader_final.xm",
46 "dat/m/FINALBAT.s3m"};
48 Mix_Music
*bgm_music
= NULL
;
51 Mix_Chunk
*c_sample
[16] = {NULL
};
55 Mix_OpenAudio(44100, AUDIO_S16
, 2, 4096);
57 Mix_AllocateChannels(16);
60 void BackgroundMusic();
73 static int hum_play
= 0;
82 if (magic_circuit
== 0) {
89 if (magic_circuit
> 0) {
90 hum_vol
= (circuit_size
* 24 / 3000)+12;
91 hum_vol
= (magic_circuit
* 96 / circuit_size
) * hum_vol
/ 36 + 32;
96 Mix_FreeChunk(c_sample
[0]);
98 c_sample
[0] = Mix_LoadWAV("dat/a/circuitcharge.wav");
99 Mix_PlayChannel(0, c_sample
[0], -1);
103 if (magic_circuit
< 0) {
104 hum_vol
= (circuit_size
- (magic_circuit
+ circuit_size
)) * 80 / 3000;
108 Mix_FreeChunk(c_sample
[0]);
110 c_sample
[0] = Mix_LoadWAV("dat/a/circuitrecover.wav");
111 Mix_PlayChannel(0, c_sample
[0], -1);
116 Mix_Volume(0, hum_vol
);
119 void TitleScreenMusic()
126 if (bgm_track
!= -1) {
128 Mix_FreeMusic(bgm_music
);
132 bgm_music
= Mix_LoadMUS(tracks
[new_track
]);
133 Mix_PlayMusic(bgm_music
, -1);
134 bgm_track
= new_track
;
137 void BackgroundMusic()
147 if (rooms
[player_room
].s_dist
<= 15) {
151 if (bgm_track
== 1) {
152 if ((rooms
[player_room
].s_dist
<= 30) && (rooms
[player_room
].s_dist
>= 10)) {
156 if (bgm_track
== 2) {
157 if ((rooms
[player_room
].s_dist
<= 45) && (rooms
[player_room
].s_dist
>= 25)) {
162 if (new_track
== -1) {
163 if ((rooms
[player_room
].s_dist
<= 30) && (rooms
[player_room
].s_dist
>= 16)) {
166 if ((rooms
[player_room
].s_dist
<= 39) && (rooms
[player_room
].s_dist
>= 31)) {
169 if (rooms
[player_room
].s_dist
>= 40) {
174 if (rooms
[player_room
].room_type
== 3) {
182 if (rooms
[player_room
].room_type
== 2) {
183 if (boss_fight_mode
== 2) {
184 if ( (current_boss
== 3) && (player_shield
== 30) ) {
185 if (boss_lives
<= 1) {
191 new_track
= 7 + current_boss
;
193 Mix_VolumeMusic(128);
199 if ( (player_room
== 0) && (current_boss
== 3) && (boss_fight_mode
>= 3) ) {
203 if (new_track
== bgm_track
) return;
205 if (bgm_track
!= -1) {
207 Mix_FreeMusic(bgm_music
);
210 if (new_track
!= -1) {
211 bgm_music
= Mix_LoadMUS(tracks
[new_track
]);
212 Mix_PlayMusic(bgm_music
, -1);
214 bgm_track
= new_track
;
219 if(bgm_track
!= -1) {
221 Mix_FreeMusic(bgm_music
);
231 for (i
= 8; i
< 16; i
++) {
232 if (Mix_Playing(i
) == 0) {
233 if (c_sample
[i
] != NULL
) {
234 Mix_FreeChunk(c_sample
[i
]);
243 void SND_Play(char *filename
, int vol
)
250 ch
= SND_GetChannel();
252 c_sample
[ch
] = Mix_LoadWAV(filename
);
254 Mix_PlayChannel(ch
, c_sample
[ch
], 0);
258 void SND_Pos(char *filename
, int vol
, int dist
)
264 if (dist
> 1600) return;
266 real_vol
= vol
* (40 - (sqrt(dist
))) / 40;
267 SND_Play(filename
, real_vol
);
270 void SND_CircuitRelease(int str
)
272 SND_Play("dat/a/circuitrelease.wav", sqrt(str
* 2 + (str
* 5300 / circuit_size
) + (str
> 100 ? 5300 : str
*53)));
275 void SND_Stop(int sample_id
)
277 Mix_HaltChannel(sample_id
);
278 Mix_FreeChunk(c_sample
[sample_id
]);
279 c_sample
[sample_id
] = NULL
;