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