Implemented -scaleup and -nosound options. Some fixes for first release.
[crow/jumpnbump.git] / menu.c
1 /*
2  * menu.c
3  * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
4  * 
5  * Copyright (C) 2001 tarzeau@space.ch
6  *
7  * Copyright (C) 2002 Florian Schulze - crow@icculus.org
8  *
9  * Portions of this code are from the MPEG software simulation group
10  * idct implementation. This code will be replaced with a new
11  * implementation soon.
12  *
13  * This file is part of Jump'n'Bump.
14  *
15  * Jump'n'Bump is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * Jump'n'Bump is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  */
29
30 #include "globals.h"
31
32 char *menu_background;
33
34 char menu_pal[768];
35 char menu_cur_pal[768];
36
37 char *message[] = {
38         "Jump 'n Bump 1.0",
39         "by Brainchild Design in 1998.",
40         "Code by Mattias Brynervall.",
41         "Graphics by Martin Magnusson",
42         "and Andreas Brynervall.",
43         "Music by Anders Nilsson.",
44         "Linux port by Chuck Mason.",
45         "New SDL port by Florian Schulze.",
46         "http://www.icculus.org/jumpnbump/",
47         "Visit our homepage at:",
48         "http://www.algonet.se/~mattiasb",
49         "Jump 'n Bump is e-mailware.",
50         "That means you're supposed to send us an e-mail!",
51         "Write for example where you're from",
52         "and what you thought about this game.",
53         "If you do that, you will greatly encourage us",
54         "to make more games for you!",
55         "Send your e-mail to: matbr656@student.liu.se",
56         "Oh, and by the way, there's a lot of secrets!",
57         "If you can't find them, you'd better ask us...",
58         "If you'd like to contact a specific member of BCD,",
59         "these are their e-mail addresses:",
60         "Andreas Brynervall: andreasb@acc.umu.se",
61         "Mattias Brynervall: matbr656@student.liu.se",
62         "Martin Magnusson: marma102@student.liu.se",
63         "Anders Nilsson: equel@swipnet.se",
64         ""
65 };
66
67 #define NUM_MESSAGES (sizeof(message)/sizeof(char *))
68
69 int menu(void)
70 {
71         int c1;
72         int esc_pressed;
73         int end_loop_flag, new_game_flag, fade_flag;
74         int mod_vol = 0, mod_fade_direction = 0;
75         int cur_message;
76         int fade_dir, fade_count, fade_tick;
77         char fade_pal[48];
78
79         if (menu_init() != 0)
80                 return 1;
81
82         mod_vol = 0;
83         mod_fade_direction = 1;
84         dj_ready_mod(MOD_MENU);
85         dj_set_mod_volume((char)mod_vol);
86         dj_set_sfx_volume(64);
87         dj_start_mod();
88         dj_set_nosound(0);
89
90         memset(fade_pal, 0, 48);
91         setpalette(240, 16, fade_pal);
92
93         fade_dir = 0;
94         fade_count = 0;
95         fade_tick = 0;
96         cur_message = NUM_MESSAGES - 1;
97
98         main_info.page_info[0].num_pobs = 0;
99         main_info.page_info[1].num_pobs = 0;
100         main_info.view_page = 0;
101         main_info.draw_page = 1;
102
103         esc_pressed = key_pressed(1);
104         end_loop_flag = new_game_flag = 0;
105
106         while (1) {
107
108                 dj_mix();
109                 intr_sysupdate();
110
111                 if (key_pressed(1) == 1 && esc_pressed == 0) {
112                         end_loop_flag = 1;
113                         new_game_flag = 0;
114                         memset(menu_pal, 0, 768);
115                         mod_fade_direction = 0;
116                 } else if (key_pressed(1) == 0)
117                         esc_pressed = 0;
118
119                 update_player_actions();
120                 for (c1 = 0; c1 < 4; c1++) {
121                         if (end_loop_flag == 1 && new_game_flag == 1) {
122                                 if ((player[c1].x >> 16) > (165 + c1 * 2)) {
123                                         if (player[c1].x_add < 0)
124                                                 player[c1].x_add += 16384;
125                                         else
126                                                 player[c1].x_add += 12288;
127                                         if (player[c1].x_add > 98304L)
128                                                 player[c1].x_add = 98304L;
129                                         player[c1].direction = 0;
130                                         if (player[c1].anim == 0) {
131                                                 player[c1].anim = 1;
132                                                 player[c1].frame = 0;
133                                                 player[c1].frame_tick = 0;
134                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
135                                         }
136                                         player[c1].enabled = 1;
137                                 }
138                                 if (!player[c1].action_up) {
139                                         if (player[c1].y_add < 0) {
140                                                 player[c1].y_add += 32768;
141                                                 if (player[c1].y_add > 0)
142                                                         player[c1].y_add = 0;
143                                         }
144                                 }
145                                 player[c1].y_add += 12288;
146                                 if (player[c1].y_add > 36864 && player[c1].anim != 3) {
147                                         player[c1].anim = 3;
148                                         player[c1].frame = 0;
149                                         player[c1].frame_tick = 0;
150                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
151                                 }
152                                 player[c1].y += player[c1].y_add;
153                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
154                                         if ((player[c1].y >> 16) > (160 + c1 * 2)) {
155                                                 player[c1].y = (160L + c1 * 2) << 16;
156                                                 player[c1].y_add = 0;
157                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
158                                                         player[c1].anim = 0;
159                                                         player[c1].frame = 0;
160                                                         player[c1].frame_tick = 0;
161                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
162                                                 }
163                                         }
164                                 } else {
165                                         if ((player[c1].y >> 16) > (138 + c1 * 2)) {
166                                                 player[c1].y = (138L + c1 * 2) << 16;
167                                                 player[c1].y_add = 0;
168                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
169                                                         player[c1].anim = 0;
170                                                         player[c1].frame = 0;
171                                                         player[c1].frame_tick = 0;
172                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
173                                                 }
174                                                 if (!player[c1].action_up)
175                                                         player[c1].jump_ready = 1;
176                                         }
177                                 }
178                                 player[c1].x += player[c1].x_add;
179                                 if ((player[c1].y >> 16) > (138 + c1 * 2)) {
180                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (190 + c1 * 2)) {
181                                                 player[c1].x = (165L + c1 * 2) << 16;
182                                                 player[c1].x_add = 0;
183                                         }
184                                         if ((player[c1].x >> 16) > (190 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
185                                                 player[c1].x = (208L + c1 * 2) << 16;
186                                                 player[c1].x_add = 0;
187                                         }
188                                 }
189                         } else {
190                                 if (player[c1].action_left && player[c1].action_right) {
191                                         if (player[c1].direction == 1) {
192                                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
193                                                         if (player[c1].x_add > 0) {
194                                                                 player[c1].x_add -= 16384;
195                                                                 if ((player[c1].y >> 16) >= (160 + c1 * 2))
196                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
197                                                         } else
198                                                                 player[c1].x_add -= 12288;
199                                                 }
200                                                 if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
201                                                         if (player[c1].x_add > 0) {
202                                                                 player[c1].x_add -= 16384;
203                                                                 if ((player[c1].y >> 16) >= (138 + c1 * 2))
204                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
205                                                         } else
206                                                                 player[c1].x_add -= 12288;
207                                                 }
208                                                 if (player[c1].x_add < -98304L)
209                                                         player[c1].x_add = -98304L;
210                                                 player[c1].direction = 1;
211                                                 if (player[c1].anim == 0) {
212                                                         player[c1].anim = 1;
213                                                         player[c1].frame = 0;
214                                                         player[c1].frame_tick = 0;
215                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
216                                                 }
217                                         } else {
218                                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
219                                                         if (player[c1].x_add < 0) {
220                                                                 player[c1].x_add += 16384;
221                                                                 if ((player[c1].y >> 16) >= (160 + c1 * 2))
222                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
223                                                         } else
224                                                                 player[c1].x_add += 12288;
225                                                 }
226                                                 if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
227                                                         if (player[c1].x_add < 0) {
228                                                                 player[c1].x_add += 16384;
229                                                                 if ((player[c1].y >> 16) >= (138 + c1 * 2))
230                                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
231                                                         } else
232                                                                 player[c1].x_add += 12288;
233                                                 }
234                                                 if (player[c1].x_add > 98304L)
235                                                         player[c1].x_add = 98304L;
236                                                 player[c1].direction = 0;
237                                                 if (player[c1].anim == 0) {
238                                                         player[c1].anim = 1;
239                                                         player[c1].frame = 0;
240                                                         player[c1].frame_tick = 0;
241                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
242                                                 }
243                                         }
244                                 } else if (player[c1].action_left) {
245                                         if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
246                                                 if (player[c1].x_add > 0) {
247                                                         player[c1].x_add -= 16384;
248                                                         if ((player[c1].y >> 16) >= (160 + c1 * 2))
249                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
250                                                 } else
251                                                         player[c1].x_add -= 12288;
252                                         }
253                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
254                                                 if (player[c1].x_add > 0) {
255                                                         player[c1].x_add -= 16384;
256                                                         if ((player[c1].y >> 16) >= (138 + c1 * 2))
257                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
258                                                 } else
259                                                         player[c1].x_add -= 12288;
260                                         }
261                                         if (player[c1].x_add < -98304L)
262                                                 player[c1].x_add = -98304L;
263                                         player[c1].direction = 1;
264                                         if (player[c1].anim == 0) {
265                                                 player[c1].anim = 1;
266                                                 player[c1].frame = 0;
267                                                 player[c1].frame_tick = 0;
268                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
269                                         }
270                                 } else if (player[c1].action_right) {
271                                         if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
272                                                 if (player[c1].x_add < 0) {
273                                                         player[c1].x_add += 16384;
274                                                         if ((player[c1].y >> 16) >= (160 + c1 * 2))
275                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
276                                                 } else
277                                                         player[c1].x_add += 12288;
278                                         }
279                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
280                                                 if (player[c1].x_add < 0) {
281                                                         player[c1].x_add += 16384;
282                                                         if ((player[c1].y >> 16) >= (138 + c1 * 2))
283                                                                 add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
284                                                 } else
285                                                         player[c1].x_add += 12288;
286                                         }
287                                         if (player[c1].x_add > 98304L)
288                                                 player[c1].x_add = 98304L;
289                                         player[c1].direction = 0;
290                                         if (player[c1].anim == 0) {
291                                                 player[c1].anim = 1;
292                                                 player[c1].frame = 0;
293                                                 player[c1].frame_tick = 0;
294                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
295                                         }
296                                 } else {
297                                         if (((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) && (player[c1].y >> 16) >= (160 + c1 * 2)) {
298                                                 if (player[c1].x_add < 0) {
299                                                         player[c1].x_add += 16384;
300                                                         if (player[c1].x_add > 0)
301                                                                 player[c1].x_add = 0;
302                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
303                                                 } else if (player[c1].x_add > 0) {
304                                                         player[c1].x_add -= 16384;
305                                                         if (player[c1].x_add < 0)
306                                                                 player[c1].x_add = 0;
307                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
308                                                 }
309                                         }
310                                         if ((((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) && (player[c1].y >> 16) >= (138 + c1 * 2))) {
311                                                 if (player[c1].x_add < 0) {
312                                                         player[c1].x_add += 16384;
313                                                         if (player[c1].x_add > 0)
314                                                                 player[c1].x_add = 0;
315                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
316                                                 } else if (player[c1].x_add > 0) {
317                                                         player[c1].x_add -= 16384;
318                                                         if (player[c1].x_add < 0)
319                                                                 player[c1].x_add = 0;
320                                                         add_object(OBJ_SMOKE, (player[c1].x >> 16) + 2 + rnd(9), (player[c1].y >> 16) + 13 + rnd(5), 0, -16384 - rnd(8192), OBJ_ANIM_SMOKE, 0);
321                                                 }
322                                         }
323                                         if (player[c1].anim == 1) {
324                                                 player[c1].anim = 0;
325                                                 player[c1].frame = 0;
326                                                 player[c1].frame_tick = 0;
327                                                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
328                                         }
329                                 }
330                                 if ((player[c1].jump_ready == 1) && player[c1].action_up) {
331                                         if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
332                                                 if ((player[c1].y >> 16) >= (160 + c1 * 2)) {
333                                                         player[c1].y_add = -280000L;
334                                                         player[c1].anim = 2;
335                                                         player[c1].frame = 0;
336                                                         player[c1].frame_tick = 0;
337                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
338                                                         player[c1].jump_ready = 0;
339                                                         dj_play_sfx(SFX_JUMP, (unsigned short)(SFX_JUMP_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
340                                                 }
341                                         } else {
342                                                 if ((player[c1].y >> 16) >= (138 + c1 * 2)) {
343                                                         player[c1].y_add = -280000L;
344                                                         player[c1].anim = 2;
345                                                         player[c1].frame = 0;
346                                                         player[c1].frame_tick = 0;
347                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
348                                                         player[c1].jump_ready = 0;
349                                                         dj_play_sfx(SFX_JUMP, (unsigned short)(SFX_JUMP_FREQ + rnd(2000) - 1000), 64, 0, 0, -1);
350                                                 }
351                                         }
352                                 }
353                                 if (!player[c1].action_up) {
354                                         if (player[c1].y_add < 0) {
355                                                 player[c1].y_add += 32768;
356                                                 if (player[c1].y_add > 0)
357                                                         player[c1].y_add = 0;
358                                         }
359                                 }
360                                 if (!player[c1].action_up)
361                                         player[c1].jump_ready = 1;
362                                 player[c1].y_add += 12288;
363                                 if (player[c1].y_add > 36864 && player[c1].anim != 3) {
364                                         player[c1].anim = 3;
365                                         player[c1].frame = 0;
366                                         player[c1].frame_tick = 0;
367                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
368                                 }
369                                 player[c1].y += player[c1].y_add;
370                                 if ((player[c1].x >> 16) <= (165 + c1 * 2) || (player[c1].x >> 16) >= (208 + c1 * 2)) {
371                                         if ((player[c1].y >> 16) > (160 + c1 * 2)) {
372                                                 player[c1].y = (160L + c1 * 2) << 16;
373                                                 player[c1].y_add = 0;
374                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
375                                                         player[c1].anim = 0;
376                                                         player[c1].frame = 0;
377                                                         player[c1].frame_tick = 0;
378                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
379                                                 }
380                                         }
381                                 } else {
382                                         if ((player[c1].y >> 16) > (138 + c1 * 2)) {
383                                                 player[c1].y = (138L + c1 * 2) << 16;
384                                                 player[c1].y_add = 0;
385                                                 if (player[c1].anim != 0 && player[c1].anim != 1) {
386                                                         player[c1].anim = 0;
387                                                         player[c1].frame = 0;
388                                                         player[c1].frame_tick = 0;
389                                                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
390                                                 }
391                                         }
392                                 }
393                                 player[c1].x += player[c1].x_add;
394                                 if ((player[c1].x >> 16) < 0) {
395                                         player[c1].x = 0;
396                                         player[c1].x_add = 0;
397                                 }
398                                 if ((player[c1].x >> 16) > 400) {
399                                         end_loop_flag = 1;
400                                         new_game_flag = 1;
401                                         memset(menu_pal, 0, 768);
402                                         mod_fade_direction = 0;
403                                 }
404                                 if ((player[c1].y >> 16) > (138 + c1 * 2)) {
405                                         if ((player[c1].x >> 16) > (165 + c1 * 2) && (player[c1].x >> 16) < (190 + c1 * 2)) {
406                                                 player[c1].x = (165L + c1 * 2) << 16;
407                                                 player[c1].x_add = 0;
408                                         }
409                                         if ((player[c1].x >> 16) > (190 + c1 * 2) && (player[c1].x >> 16) < (208 + c1 * 2)) {
410                                                 player[c1].x = (208L + c1 * 2) << 16;
411                                                 player[c1].x_add = 0;
412                                         }
413                                 }
414                         }
415                         player[c1].frame_tick++;
416                         if (player[c1].frame_tick >= player_anims[player[c1].anim].frame[player[c1].frame].ticks) {
417                                 player[c1].frame++;
418                                 if (player[c1].frame >= player_anims[player[c1].anim].num_frames)
419                                         player[c1].frame = player_anims[player[c1].anim].restart_frame;
420                                 player[c1].frame_tick = 0;
421                         }
422                         player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image + player[c1].direction * 9;
423                 }
424
425                 dj_mix();
426
427                 main_info.page_info[main_info.draw_page].num_pobs = 0;
428
429                 for (c1 = 3; c1 >= 0; c1--)
430                         add_pob(main_info.draw_page, player[c1].x >> 16, player[c1].y >> 16, player[c1].image + c1 * 18, &rabbit_gobs);
431
432                 update_objects();
433
434                 draw_begin();
435                 draw_pobs(main_info.draw_page);
436                 draw_end();
437
438                 dj_mix();
439
440                 if (mod_fade_direction == 1) {
441                         if (mod_vol < 35) {
442                                 mod_vol++;
443                                 dj_set_mod_volume((char)mod_vol);
444                         }
445                 } else {
446                         if (mod_vol > 0) {
447                                 mod_vol--;
448                                 dj_set_mod_volume((char)mod_vol);
449                         }
450                 }
451
452                 fade_flag = 0;
453                 for (c1 = 0; c1 < 720; c1++) {
454                         if (menu_cur_pal[c1] < menu_pal[c1]) {
455                                 menu_cur_pal[c1]++;
456                                 fade_flag = 1;
457                         } else if (menu_cur_pal[c1] > menu_pal[c1]) {
458                                 menu_cur_pal[c1]--;
459                                 fade_flag = 2;
460                         }
461                 }
462                 if (fade_flag == 0 && end_loop_flag == 1) {
463                         menu_deinit();
464                         if (new_game_flag == 1)
465                                 return 0;
466                         else
467                                 return 1;
468                 }
469                 switch (fade_dir) {
470                 case 0:
471                         if (fade_count < 30) {
472                                 for (c1 = 0; c1 < 48; c1++) {
473                                         if (fade_pal[c1] > 0)
474                                                 fade_pal[c1]--;
475                                 }
476                                 fade_count++;
477                         } else {
478                                 draw_begin();
479                                 clear_lines(0, 220, 20, 0);
480                                 clear_lines(1, 220, 20, 0);
481
482                                 cur_message++;
483                                 if (cur_message >= NUM_MESSAGES)
484                                         cur_message -= NUM_MESSAGES;
485                                 put_text(0, 200, 220, message[cur_message], 2);
486                                 put_text(1, 200, 220, message[cur_message], 2);
487                                 fade_dir = 1;
488                                 fade_count = 0;
489                                 fade_tick = 0;
490                                 draw_end();
491                         }
492                         break;
493                 case 1:
494                         if (fade_count < 100) {
495                                 for (c1 = 0; c1 < 48; c1++) {
496                                         if (fade_pal[c1] < menu_pal[c1 + 720])
497                                                 fade_pal[c1]++;
498                                 }
499                                 fade_count++;
500                         } else {
501                                 fade_dir = 0;
502                                 fade_count = 0;
503                                 fade_tick = 0;
504                         }
505                         break;
506                 }
507
508                 for (c1 = 0; c1 < 48; c1++) {
509                         if (fade_pal[c1] > menu_pal[c1 + 720])
510                                 fade_pal[c1]--;
511                 }
512
513                 main_info.draw_page ^= 1;
514                 main_info.view_page ^= 1;
515
516                 flippage(main_info.view_page);
517
518                 wait_vrt(1);
519
520                 if (fade_flag != 0) {
521                         setpalette(0, 240, menu_cur_pal);
522                 }
523
524                 setpalette(240, 16, fade_pal);
525
526                 dj_mix();
527
528                 draw_begin();
529                 redraw_pob_backgrounds(main_info.draw_page);
530                 draw_end();
531
532         }
533
534         menu_deinit();
535         return 0;
536
537 }
538
539
540 int menu_init(void)
541 {
542         FILE *handle;
543         int c1;
544
545         fillpalette(0, 0, 0);
546
547         if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) {
548                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
549                 return 1;
550         }
551         if (read_pcx(handle, background_pic, 102400, menu_pal) != 0) {
552                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
553                 return 1;
554         }
555         fclose(handle);
556         if ((handle = dat_open("menumask.pcx", datfile_name, "rb")) == 0) {
557                 strcpy(main_info.error_str, "Error loading 'menumask.pcx', aborting...\n");
558                 return 1;
559         }
560         if (read_pcx(handle, mask_pic, 102400, 0) != 0) {
561                 strcpy(main_info.error_str, "Error loading 'menumask.pcx', aborting...\n");
562                 return 1;
563         }
564         fclose(handle);
565         memset(menu_cur_pal, 0, 768);
566
567         recalculate_gob(&rabbit_gobs, menu_pal);
568         recalculate_gob(&font_gobs, menu_pal);
569         recalculate_gob(&object_gobs, menu_pal);
570         register_background(background_pic, menu_pal);
571         register_mask(mask_pic);
572
573         for (c1 = 0; c1 < 4; c1++) {
574                 player[c1].enabled = 0;
575                 player[c1].x = (long) rnd(150) << 16;
576                 player[c1].y = (160L + c1 * 2) << 16;
577                 player[c1].x_add = 0;
578                 player[c1].y_add = 0;
579                 player[c1].direction = rnd(2);
580                 player[c1].jump_ready = 1;
581                 player[c1].anim = 0;
582                 player[c1].frame = 0;
583                 player[c1].frame_tick = 0;
584                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image;
585         }
586
587         for (c1 = 0; c1 < NUM_OBJECTS; c1++)
588                 objects[c1].used = 0;
589
590         main_info.page_info[0].num_pobs = 0;
591         main_info.page_info[1].num_pobs = 0;
592
593         return 0;
594
595 }
596
597
598 void menu_deinit(void)
599 {
600         dj_set_nosound(1);
601 }