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