e021b4ed36435f3a9ebcca500b23037c383d756b
[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         int esc_pressed;
42         int end_loop_flag, new_game_flag, fade_flag;
43         int 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((char)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_begin();
404                 draw_pobs(main_info.draw_page);
405                 draw_end();
406
407                 dj_mix();
408
409                 if (mod_fade_direction == 1) {
410                         if (mod_vol < 35) {
411                                 mod_vol++;
412                                 dj_set_mod_volume((char)mod_vol);
413                         }
414                 } else {
415                         if (mod_vol > 0) {
416                                 mod_vol--;
417                                 dj_set_mod_volume((char)mod_vol);
418                         }
419                 }
420
421                 fade_flag = 0;
422                 for (c1 = 0; c1 < 720; c1++) {
423                         if (menu_cur_pal[c1] < menu_pal[c1]) {
424                                 menu_cur_pal[c1]++;
425                                 fade_flag = 1;
426                         } else if (menu_cur_pal[c1] > menu_pal[c1]) {
427                                 menu_cur_pal[c1]--;
428                                 fade_flag = 2;
429                         }
430                 }
431                 if (fade_flag == 0 && end_loop_flag == 1) {
432                         menu_deinit();
433                         if (new_game_flag == 1)
434                                 return 0;
435                         else
436                                 return 1;
437                 }
438                 switch (fade_dir) {
439                 case 0:
440                         if (fade_count < 30) {
441                                 for (c1 = 0; c1 < 48; c1++) {
442                                         if (fade_pal[c1] > 0)
443                                                 fade_pal[c1]--;
444                                 }
445                                 fade_count++;
446                         } else {
447                                 draw_begin();
448                                 clear_lines(0, 220, 20, 0);
449                                 clear_lines(1, 220, 20, 0);
450
451                                 cur_message++;
452                                 if (cur_message >= NUM_MESSAGES)
453                                         cur_message -= NUM_MESSAGES;
454                                 put_text(0, 200, 220, message[cur_message], 2);
455                                 put_text(1, 200, 220, message[cur_message], 2);
456                                 fade_dir = 1;
457                                 fade_count = 0;
458                                 fade_tick = 0;
459                                 draw_end();
460                         }
461                         break;
462                 case 1:
463                         if (fade_count < 100) {
464                                 for (c1 = 0; c1 < 48; c1++) {
465                                         if (fade_pal[c1] < menu_pal[c1 + 720])
466                                                 fade_pal[c1]++;
467                                 }
468                                 fade_count++;
469                         } else {
470                                 fade_dir = 0;
471                                 fade_count = 0;
472                                 fade_tick = 0;
473                         }
474                         break;
475                 }
476
477                 for (c1 = 0; c1 < 48; c1++) {
478                         if (fade_pal[c1] > menu_pal[c1 + 720])
479                                 fade_pal[c1]--;
480                 }
481
482                 main_info.draw_page ^= 1;
483                 main_info.view_page ^= 1;
484
485                 flippage(main_info.view_page);
486
487                 wait_vrt(1);
488
489                 if (fade_flag != 0) {
490                         setpalette(0, 240, menu_cur_pal);
491                 }
492
493                 setpalette(240, 16, fade_pal);
494
495                 dj_mix();
496
497                 draw_begin();
498                 redraw_pob_backgrounds(main_info.draw_page);
499                 draw_end();
500
501         }
502
503         menu_deinit();
504         return 0;
505
506 }
507
508
509 int menu_init(void)
510 {
511         FILE *handle;
512         int c1;
513
514         fillpalette(0, 0, 0);
515
516         if ((handle = dat_open("menu.pcx", datfile_name, "rb")) == 0) {
517                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
518                 return 1;
519         }
520         if (read_pcx(handle, background_pic, 102400, menu_pal) != 0) {
521                 strcpy(main_info.error_str, "Error loading 'menu.pcx', aborting...\n");
522                 return 1;
523         }
524         fclose(handle);
525         if ((handle = dat_open("menumask.pcx", datfile_name, "rb")) == 0) {
526                 strcpy(main_info.error_str, "Error loading 'menumask.pcx', aborting...\n");
527                 return 1;
528         }
529         if (read_pcx(handle, mask_pic, 102400, 0) != 0) {
530                 strcpy(main_info.error_str, "Error loading 'menumask.pcx', aborting...\n");
531                 return 1;
532         }
533         fclose(handle);
534         memset(menu_cur_pal, 0, 768);
535
536         recalculate_gob(&rabbit_gobs, menu_pal);
537         recalculate_gob(&font_gobs, menu_pal);
538         recalculate_gob(&object_gobs, menu_pal);
539         register_background(background_pic, menu_pal);
540         register_mask(mask_pic);
541
542         for (c1 = 0; c1 < 4; c1++) {
543                 player[c1].enabled = 0;
544                 player[c1].x = (long) rnd(150) << 16;
545                 player[c1].y = (160L + c1 * 2) << 16;
546                 player[c1].x_add = 0;
547                 player[c1].y_add = 0;
548                 player[c1].direction = rnd(2);
549                 player[c1].jump_ready = 1;
550                 player[c1].anim = 0;
551                 player[c1].frame = 0;
552                 player[c1].frame_tick = 0;
553                 player[c1].image = player_anims[player[c1].anim].frame[player[c1].frame].image;
554         }
555
556         for (c1 = 0; c1 < NUM_OBJECTS; c1++)
557                 objects[c1].used = 0;
558
559         main_info.page_info[0].num_pobs = 0;
560         main_info.page_info[1].num_pobs = 0;
561
562         return 0;
563
564 }
565
566
567 void menu_deinit(void)
568 {
569         dj_set_nosound(1);
570 }