1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
29 /* for DrawSetupScreen(), HandleSetupScreen() */
30 #define SETUP_SCREEN_POS_START 2
31 #define SETUP_SCREEN_POS_END (SCR_FIELDY - 1)
32 #define SETUP_SCREEN_POS_EMPTY1 (SETUP_SCREEN_POS_END - 2)
33 #define SETUP_SCREEN_POS_EMPTY2 (SETUP_SCREEN_POS_END - 2)
35 /* for HandleSetupInputScreen() */
36 #define SETUPINPUT_SCREEN_POS_START 2
37 #define SETUPINPUT_SCREEN_POS_END (SCR_FIELDY - 2)
38 #define SETUPINPUT_SCREEN_POS_EMPTY1 (SETUPINPUT_SCREEN_POS_START + 3)
39 #define SETUPINPUT_SCREEN_POS_EMPTY2 (SETUPINPUT_SCREEN_POS_END - 1)
41 /* for HandleChooseLevel() */
42 #define MAX_LEVEL_SERIES_ON_SCREEN (SCR_FIELDY - 2)
45 extern unsigned char get_ascii(KeySym);
50 int x = SX + (SXSIZE - strlen(PROGRAM_TITLE_STRING) * FONT1_XSIZE) / 2;
52 DrawText(x, SY + 8, PROGRAM_TITLE_STRING, FS_BIG, FC_YELLOW);
53 DrawTextFCentered(46, FC_RED, COPYRIGHT_STRING);
59 char *name_text = (!options.network && setup.team_mode ? "Team:" : "Name:");
63 XAutoRepeatOn(display);
65 /* needed if last screen was the playing screen, invoked from level editor */
66 if (level_editor_test_game)
68 game_status = LEVELED;
73 /* needed if last screen was the editor screen */
74 UndrawSpecialEditorDoor();
76 /* map gadgets for main menu screen */
79 /* level_nr may have set to value over handicap with level editor */
80 if (setup.handicap && level_nr > leveldir[leveldir_nr].handicap_level)
81 level_nr = leveldir[leveldir_nr].handicap_level;
88 DrawText(SX + 32, SY + 2*32, name_text, FS_BIG, FC_GREEN);
89 DrawText(SX + 6*32, SY + 2*32, setup.player_name, FS_BIG, FC_RED);
90 DrawText(SX + 32, SY + 3*32, "Level:", FS_BIG, FC_GREEN);
91 DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
92 (leveldir[leveldir_nr].readonly ? FC_RED : FC_YELLOW));
93 DrawText(SX + 32, SY + 4*32, "Hall Of Fame", FS_BIG, FC_GREEN);
94 DrawText(SX + 32, SY + 5*32, "Level Creator", FS_BIG, FC_GREEN);
95 DrawText(SY + 32, SY + 6*32, "Info Screen", FS_BIG, FC_GREEN);
96 DrawText(SX + 32, SY + 7*32, "Start Game", FS_BIG, FC_GREEN);
97 DrawText(SX + 32, SY + 8*32, "Setup", FS_BIG, FC_GREEN);
98 DrawText(SX + 32, SY + 9*32, "Quit", FS_BIG, FC_GREEN);
100 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
102 DrawTextF(7*32 + 6, 3*32 + 9, FC_RED, "%d-%d",
103 leveldir[leveldir_nr].first_level,
104 leveldir[leveldir_nr].last_level);
106 if (leveldir[leveldir_nr].readonly)
108 DrawTextF(15*32 + 6, 3*32 + 9 - 7, FC_RED, "READ");
109 DrawTextF(15*32 + 6, 3*32 + 9 + 7, FC_RED, "ONLY");
113 DrawGraphic(0, i, GFX_KUGEL_BLAU);
114 DrawGraphic(10, 3, GFX_PFEIL_LEFT);
115 DrawGraphic(14, 3, GFX_PFEIL_RIGHT);
117 DrawText(SX + 56, SY + 326, "A Game by Artsoft Entertainment",
120 if (leveldir[leveldir_nr].name)
122 int len = strlen(leveldir[leveldir_nr].name);
123 int lxpos = SX + (SXSIZE - len * FONT4_XSIZE) / 2;
124 int lypos = SY + 352;
126 DrawText(lxpos, lypos, leveldir[leveldir_nr].name, FS_SMALL, FC_SPECIAL2);
131 HandleMainMenu(0,0, 0,0, MB_MENU_INITIALIZE);
134 if (TAPE_IS_EMPTY(tape))
136 DrawCompleteVideoDisplay();
138 OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
146 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
148 static int choice = 3;
149 static int redraw = TRUE;
150 int x = (mx + 32 - SX) / 32, y = (my + 32 - SY) / 32;
152 if (redraw || button == MB_MENU_INITIALIZE)
154 DrawGraphic(0, choice - 1, GFX_KUGEL_ROT);
158 if (button == MB_MENU_INITIALIZE)
163 if (dx && choice == 4)
165 x = (dx < 0 ? 11 : 15);
182 if (!mx && !my && !dx && !dy)
188 if (y == 4 && ((x == 11 && level_nr > leveldir[leveldir_nr].first_level) ||
189 (x == 15 && level_nr < leveldir[leveldir_nr].last_level)) &&
192 static unsigned long level_delay = 0;
193 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
194 int new_level_nr, old_level_nr = level_nr;
195 int font_color = (leveldir[leveldir_nr].readonly ? FC_RED : FC_YELLOW);
197 new_level_nr = level_nr + (x == 11 ? -step : +step);
198 if (new_level_nr < leveldir[leveldir_nr].first_level)
199 new_level_nr = leveldir[leveldir_nr].first_level;
200 if (new_level_nr > leveldir[leveldir_nr].last_level)
201 new_level_nr = leveldir[leveldir_nr].last_level;
203 if (setup.handicap && new_level_nr > leveldir[leveldir_nr].handicap_level)
204 new_level_nr = leveldir[leveldir_nr].handicap_level;
206 if (old_level_nr == new_level_nr ||
207 !DelayReached(&level_delay, GADGET_FRAME_DELAY))
210 level_nr = new_level_nr;
212 DrawTextExt(drawto, gc, SX + 11 * 32, SY + 3 * 32,
213 int2str(level_nr, 3), FS_BIG, font_color);
214 DrawTextExt(window, gc, SX + 11 * 32, SY + 3 * 32,
215 int2str(level_nr, 3), FS_BIG, font_color);
218 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, TRUE);
222 DrawCompleteVideoDisplay();
224 /* needed because DrawMicroLevel() takes some time */
226 XSync(display, FALSE);
227 DelayReached(&level_delay, 0); /* reset delay counter */
229 else if (x == 1 && y >= 3 && y <= 10)
235 DrawGraphic(0, y-1, GFX_KUGEL_ROT);
236 DrawGraphic(0, choice - 1, GFX_KUGEL_BLAU);
244 game_status = TYPENAME;
245 HandleTypeName(strlen(setup.player_name), 0);
251 game_status = CHOOSELEVEL;
252 SaveLevelSetup_LastSeries();
253 SaveLevelSetup_SeriesInfo(leveldir_nr);
259 game_status = HALLOFFAME;
264 if (leveldir[leveldir_nr].readonly &&
265 strcmp(setup.player_name, "Artsoft") != 0)
266 Request("This level is read only !", REQ_CONFIRM);
267 game_status = LEVELED;
272 game_status = HELPSCREEN;
277 if (setup.autorecord)
278 TapeStartRecording();
282 SendToServer_StartPlaying();
286 game_status = PLAYING;
298 SaveLevelSetup_LastSeries();
299 SaveLevelSetup_SeriesInfo(leveldir_nr);
300 if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED))
301 game_status = EXITGAME;
311 if (game_status == MAINMENU)
313 DrawMicroLevel(MICROLEV_XPOS, MICROLEV_YPOS, FALSE);
318 #define MAX_HELPSCREEN_ELS 10
322 static long helpscreen_state;
323 static int helpscreen_step[MAX_HELPSCREEN_ELS];
324 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
325 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
326 static int helpscreen_action[] =
328 GFX_SPIELER1_DOWN,4,2,
330 GFX_SPIELER1_LEFT,4,2,
331 GFX_SPIELER1_RIGHT,4,2,
332 GFX_SPIELER1_PUSH_LEFT,4,2,
333 GFX_SPIELER1_PUSH_RIGHT,4,2, HA_NEXT,
334 GFX_ERDREICH,1,100, HA_NEXT,
335 GFX_LEERRAUM,1,100, HA_NEXT,
336 GFX_MORAST_LEER,1,100, HA_NEXT,
337 GFX_BETON,1,100, HA_NEXT,
338 GFX_MAUERWERK,1,100, HA_NEXT,
339 GFX_MAUER_L1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
340 GFX_MAUER_R1, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
341 GFX_MAUER_UP, 3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
342 GFX_MAUER_DOWN,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10, HA_NEXT,
343 GFX_UNSICHTBAR,1,100, HA_NEXT,
344 GFX_FELSBODEN,1,100, HA_NEXT,
345 GFX_CHAR_A,30,4, GFX_CHAR_AUSRUF,32,4, HA_NEXT,
346 GFX_EDELSTEIN,2,5, HA_NEXT,
347 GFX_DIAMANT,2,5, HA_NEXT,
348 GFX_EDELSTEIN_BD,2,5, HA_NEXT,
349 GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
350 GFX_EDELSTEIN_LILA,2,5, HA_NEXT,
351 GFX_FELSBROCKEN,4,5, HA_NEXT,
352 GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
353 GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10, HA_NEXT,
354 GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10, HA_NEXT,
355 GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10, HA_NEXT,
356 GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
357 GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
358 GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
359 GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
360 GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
361 GFX_EDELSTEIN_LILA,1,10, HA_NEXT,
362 GFX_GEBLUBBER,4,4, HA_NEXT,
363 GFX_SCHLUESSEL1,4,25, HA_NEXT,
364 GFX_PFORTE1,4,25, HA_NEXT,
365 GFX_PFORTE1X,4,25, HA_NEXT,
366 GFX_DYNAMIT_AUS,1,100, HA_NEXT,
367 GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10, HA_NEXT,
368 GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
369 GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
370 GFX_LEERRAUM,1,10, HA_NEXT,
371 GFX_DYNABOMB_NR,1,100, HA_NEXT,
372 GFX_DYNABOMB_SZ,1,100, HA_NEXT,
373 GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
374 GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
375 GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
376 GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3, HA_NEXT,
377 GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
378 GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
379 GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
380 GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1, HA_NEXT,
381 GFX_BUTTERFLY,2,2, HA_NEXT,
382 GFX_FIREFLY,2,2, HA_NEXT,
383 GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
384 GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
385 GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
386 GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3, HA_NEXT,
387 GFX_MAMPFER+0,4,1, GFX_MAMPFER+3,1,1, GFX_MAMPFER+2,1,1,
388 GFX_MAMPFER+1,1,1, GFX_MAMPFER+0,1,1, HA_NEXT,
389 GFX_MAMPFER2+0,4,1, GFX_MAMPFER2+3,1,1, GFX_MAMPFER2+2,1,1,
390 GFX_MAMPFER2+1,1,1, GFX_MAMPFER2+0,1,1, HA_NEXT,
391 GFX_ROBOT+0,4,1, GFX_ROBOT+3,1,1, GFX_ROBOT+2,1,1,
392 GFX_ROBOT+1,1,1, GFX_ROBOT+0,1,1, HA_NEXT,
396 GFX_MOLE_RIGHT,4,2, HA_NEXT,
397 GFX_PINGUIN_DOWN,4,2,
399 GFX_PINGUIN_LEFT,4,2,
400 GFX_PINGUIN_RIGHT,4,2, HA_NEXT,
401 GFX_SCHWEIN_DOWN,4,2,
403 GFX_SCHWEIN_LEFT,4,2,
404 GFX_SCHWEIN_RIGHT,4,2, HA_NEXT,
408 GFX_DRACHE_RIGHT,4,2, HA_NEXT,
409 GFX_SONDE_START,8,1, HA_NEXT,
410 GFX_ABLENK,4,1, HA_NEXT,
411 GFX_BIRNE_AUS,1,25, GFX_BIRNE_EIN,1,25, HA_NEXT,
412 GFX_ZEIT_VOLL,1,25, GFX_ZEIT_LEER,1,25, HA_NEXT,
413 GFX_TROPFEN,1,25, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10, HA_NEXT,
414 GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50, HA_NEXT,
415 GFX_AMOEBE_LEBT,4,40, HA_NEXT,
416 GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2, HA_NEXT,
417 GFX_AMOEBE_LEBT,1,25, GFX_AMOEBE_TOT,1,25, GFX_EXPLOSION,8,1,
418 GFX_DIAMANT,1,10, HA_NEXT,
419 GFX_LIFE,1,100, HA_NEXT,
420 GFX_LIFE_ASYNC,1,100, HA_NEXT,
421 GFX_SIEB_INAKTIV,4,2, HA_NEXT,
422 GFX_SIEB2_INAKTIV,4,2, HA_NEXT,
423 GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
424 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
425 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
426 GFX_AUSGANG_AUF+0,4,2, GFX_AUSGANG_AUF+3,1,2,
427 GFX_AUSGANG_AUF+2,1,2, GFX_AUSGANG_AUF+1,1,2, HA_NEXT,
428 GFX_SOKOBAN_OBJEKT,1,100, HA_NEXT,
429 GFX_SOKOBAN_FELD_LEER,1,100, HA_NEXT,
430 GFX_SOKOBAN_FELD_VOLL,1,100, HA_NEXT,
431 GFX_SPEED_PILL,1,100, HA_NEXT,
434 static char *helpscreen_eltext[][2] =
436 {"THE HERO:", "(Is _this_ guy good old Rockford?)"},
437 {"Normal sand:", "You can dig through it"},
438 {"Empty field:", "You can walk through it"},
439 {"Quicksand: You cannot pass it,", "but rocks can fall though it"},
440 {"Massive Wall:", "Nothing can go through it"},
441 {"Normal Wall: You can't go through", "it, but you can bomb it away"},
442 {"Growing Wall: Grows in several di-", "rections if there is an empty field"},
443 {"Invisible Wall: Behaves like normal","wall, but is invisible"},
444 {"Old Wall: Like normal wall, but", "some things can fall down from it"},
445 {"Letter Wall: Looks like a letter,", "behaves like a normal wall"},
446 {"Emerald: You must collect enough of","them to finish a level"},
447 {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
448 {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
449 {"Colorful Gems:", "Seem to behave like Emeralds"},
450 {"Rock: Smashes several things;", "Can be moved by the player"},
451 {"Bomb: You can move it, but be", "careful when dropping it"},
452 {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
453 {"Wall with an emerald inside:", "Bomb the wall away to get it"},
454 {"Wall with a diamond inside:", "Bomb the wall away to get it"},
455 {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
456 {"Wall with colorful gem inside:", "Bomb the wall away to get it"},
457 {"Acid: Things that fall in are gone", "forever (including our hero)"},
458 {"Key: Opens the door that has the", "same color (red/yellow/green/blue)"},
459 {"Door: Can be opened by the key", "with the same color"},
460 {"Door: You have to find out the", "right color of the key for it"},
461 {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
462 {"Dynamite: This one explodes after", "a few seconds"},
463 {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
464 {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
465 {"Dyna Bomb: Increases the size of", "explosion of dyna bombs"},
466 {"Spaceship: Moves at the left side", "of walls; don't touch it!"},
467 {"Bug: Moves at the right side", "of walls; don't touch it!"},
468 {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
469 {"Firefly: Moves at the left side", "of walls; don't touch it!"},
470 {"Pacman: Eats the amoeba and you,", "if you're not careful"},
471 {"Cruncher: Eats diamonds and you,", "if you're not careful"},
472 {"Cruncher (BD style):", "Eats almost everything"},
473 {"Robot: Tries to kill the player", ""},
474 {"The mole: Eats the amoeba and turns","empty space into normal sand"},
475 {"The penguin: Guide him to the exit,","but keep him away from monsters!"},
476 {"The Pig: Harmless, but eats all", "gems it can get"},
477 {"The Dragon: Breathes fire,", "especially to some monsters"},
478 {"Sonde: Follows you everywhere;", "harmless, but may block your way"},
479 {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
480 {"Light Bulb: All of them must be", "switched on to finish a level"},
481 {"Extra Time Orb: Adds some seconds", "to the time available for the level"},
482 {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
483 {"Dead Amoeba: Does not grow, but", "can still kill bugs and spaceships"},
484 {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
485 {"Dropping Amoeba: This one makes", "drops that grow to a new amoeba"},
486 {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
487 {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
488 {"Biomaze: A bit like the 'Game Of", "Life', but builds crazy mazes"},
489 {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
490 {"Magic Wall (BD style):", "Changes rocks and BD style diamonds"},
491 {"Exit door: Opens if you have enough","emeralds to finish the level"},
492 {"Open exit door: Enter here to leave","the level and exit the actual game"},
493 {"Sokoban element: Object which must", "be pushed to an empty field"},
494 {"Sokoban element: Empty field where", "a Sokoban object can be placed on"},
495 {"Sokoban element: Field with object", "which can be pushed away"},
496 {"Speed pill: Lets the player run", "twice as fast as normally"},
498 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
500 static char *helpscreen_music[][3] =
502 { "Alchemy", "Ian Boddy", "Drive" },
503 { "The Chase", "Propaganda", "A Secret Wish" },
504 { "Network 23", "Tangerine Dream", "Exit" },
505 { "Czardasz", "Robert Pieculewicz", "Czardasz" },
506 { "21st Century Common Man", "Tangerine Dream", "Tyger" },
507 { "Voyager", "The Alan Parsons Project","Pyramid" },
508 { "Twilight Painter", "Tangerine Dream", "Heartbreakers" }
510 static int helpscreen_musicpos;
512 void DrawHelpScreenElAction(int start)
516 int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
518 while(helpscreen_action[j] != HA_END)
520 if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
522 else if (i<start || helpscreen_delay[i-start])
524 if (i>=start && helpscreen_delay[i-start])
525 helpscreen_delay[i-start]--;
527 while(helpscreen_action[j] != HA_NEXT)
534 j += 3*helpscreen_step[i-start];
535 graphic = helpscreen_action[j++];
537 if (helpscreen_frame[i-start])
539 frame = helpscreen_action[j++] - helpscreen_frame[i-start];
540 helpscreen_frame[i-start]--;
545 helpscreen_frame[i-start] = helpscreen_action[j++]-1;
548 helpscreen_delay[i-start] = helpscreen_action[j++] - 1;
550 if (helpscreen_action[j] == HA_NEXT)
552 if (!helpscreen_frame[i-start])
553 helpscreen_step[i-start] = 0;
557 if (!helpscreen_frame[i-start])
558 helpscreen_step[i-start]++;
559 while(helpscreen_action[j] != HA_NEXT)
564 DrawGraphicExt(drawto, gc, xstart, ystart+(i-start)*ystep, graphic+frame);
575 void DrawHelpScreenElText(int start)
578 int xstart = SX + 56, ystart = SY + 65 + 2 * 32, ystep = TILEY + 4;
579 int ybottom = SYSIZE - 20;
584 DrawTextFCentered(100, FC_GREEN, "The game elements:");
586 for(i=start; i < start + MAX_HELPSCREEN_ELS && i < num_helpscreen_els; i++)
589 ystart + (i - start) * ystep + (*helpscreen_eltext[i][1] ? 0 : 8),
590 helpscreen_eltext[i][0], FS_SMALL, FC_YELLOW);
591 DrawText(xstart, ystart + (i - start) * ystep + 16,
592 helpscreen_eltext[i][1], FS_SMALL, FC_YELLOW);
595 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
598 void DrawHelpScreenMusicText(int num)
600 int ystart = 150, ystep = 30;
601 int ybottom = SYSIZE - 20;
607 DrawTextFCentered(100, FC_GREEN, "The game background music loops:");
609 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
611 DrawTextFCentered(ystart + 1 * ystep, FC_RED, "\"%s\"",
612 helpscreen_music[num][0]);
613 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
615 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
616 "%s", helpscreen_music[num][1]);
617 DrawTextFCentered(ystart + 4 * ystep, FC_YELLOW,
619 DrawTextFCentered(ystart + 5 * ystep, FC_RED, "\"%s\"",
620 helpscreen_music[num][2]);
622 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
624 PlaySoundLoop(background_loop[num]);
627 void DrawHelpScreenCreditsText()
629 int ystart = 150, ystep = 30;
630 int ybottom = SYSIZE - 20;
636 DrawTextFCentered(100, FC_GREEN,
638 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
639 "DOS/Windows port of the game:");
640 DrawTextFCentered(ystart + 1 * ystep, FC_RED,
642 DrawTextFCentered(ystart + 2 * ystep, FC_YELLOW,
643 "Additional toons:");
644 DrawTextFCentered(ystart + 3 * ystep, FC_RED,
646 DrawTextFCentered(ystart + 5 * ystep, FC_YELLOW,
647 "...and many thanks to all contributors");
648 DrawTextFCentered(ystart + 6 * ystep, FC_YELLOW,
651 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for next page");
654 void DrawHelpScreenContactText()
656 int ystart = 150, ystep = 30;
657 int ybottom = SYSIZE - 20;
662 DrawTextFCentered(100, FC_GREEN, "Program information:");
664 DrawTextFCentered(ystart + 0 * ystep, FC_YELLOW,
665 "This game is Freeware!");
666 DrawTextFCentered(ystart + 1 * ystep, FC_YELLOW,
667 "If you like it, send e-mail to:");
668 DrawTextFCentered(ystart + 2 * ystep, FC_RED,
669 "aeglos@valinor.owl.de");
670 DrawTextFCentered(ystart + 3 * ystep, FC_YELLOW,
672 DrawTextFCentered(ystart + 4 * ystep + 0, FC_RED,
674 DrawTextFCentered(ystart + 4 * ystep + 20, FC_RED,
676 DrawTextFCentered(ystart + 4 * ystep + 40, FC_RED,
678 DrawTextFCentered(ystart + 4 * ystep + 60, FC_RED,
681 DrawTextFCentered(ystart + 7 * ystep, FC_YELLOW,
682 "If you have created new levels,");
683 DrawTextFCentered(ystart + 8 * ystep, FC_YELLOW,
684 "send them to me to include them!");
685 DrawTextFCentered(ystart + 9 * ystep, FC_YELLOW,
688 DrawTextFCentered(ybottom, FC_BLUE, "Press any key or button for main menu");
691 void DrawHelpScreen()
696 CloseDoor(DOOR_CLOSE_2);
698 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
699 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
700 helpscreen_musicpos = 0;
701 helpscreen_state = 0;
702 DrawHelpScreenElText(0);
703 DrawHelpScreenElAction(0);
707 PlaySoundLoop(SND_RHYTHMLOOP);
710 void HandleHelpScreen(int button)
712 static unsigned long hs_delay = 0;
713 int num_helpscreen_els_pages =
714 (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
715 int button_released = !button;
720 if (helpscreen_state < num_helpscreen_els_pages - 1)
722 for(i=0;i<MAX_HELPSCREEN_ELS;i++)
723 helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
725 DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
726 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
728 else if (helpscreen_state < num_helpscreen_els_pages + num_bg_loops - 1)
731 DrawHelpScreenMusicText(helpscreen_state - num_helpscreen_els_pages);
733 else if (helpscreen_state == num_helpscreen_els_pages + num_bg_loops - 1)
736 DrawHelpScreenCreditsText();
738 else if (helpscreen_state == num_helpscreen_els_pages + num_bg_loops)
741 DrawHelpScreenContactText();
747 game_status = MAINMENU;
752 if (DelayReached(&hs_delay,GAME_FRAME_DELAY * 2))
754 if (helpscreen_state<num_helpscreen_els_pages)
755 DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
763 void HandleTypeName(int newxpos, KeySym key)
765 static int xpos = 0, ypos = 2;
770 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
771 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
775 if (((key >= XK_A && key <= XK_Z) || (key >= XK_a && key <= XK_z)) &&
776 xpos < MAX_PLAYER_NAME_LEN)
780 if (key >= XK_A && key <= XK_Z)
781 ascii = 'A' + (char)(key - XK_A);
783 ascii = 'a' + (char)(key - XK_a);
785 setup.player_name[xpos] = ascii;
786 setup.player_name[xpos + 1] = 0;
788 DrawTextExt(drawto, gc, SX + 6*32, SY + ypos*32,
789 setup.player_name, FS_BIG, FC_YELLOW);
790 DrawTextExt(window, gc, SX + 6*32, SY + ypos*32,
791 setup.player_name, FS_BIG, FC_YELLOW);
792 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
794 else if ((key == XK_Delete || key == XK_BackSpace) && xpos > 0)
797 setup.player_name[xpos] = 0;
798 DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
799 DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
801 else if (key == XK_Return && xpos > 0)
803 DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
804 DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
807 game_status = MAINMENU;
813 void DrawChooseLevel()
816 CloseDoor(DOOR_CLOSE_2);
820 HandleChooseLevel(0,0, 0,0, MB_MENU_INITIALIZE);
823 static void drawChooseLevelList(int first_entry, int num_page_entries)
826 char buffer[SCR_FIELDX * 2];
829 DrawText(SX, SY, "Level Directories", FS_BIG, FC_GREEN);
831 for(i=0; i<num_page_entries; i++)
834 strncpy(buffer, leveldir[first_entry + i].name_short , SCR_FIELDX - 1);
835 buffer[SCR_FIELDX - 1] = '\0';
837 strncpy(buffer, leveldir[first_entry + i].name , (SCR_FIELDX - 1) * 2);
838 buffer[(SCR_FIELDX - 1) * 2] = '\0';
841 DrawText(SX + 32, SY + (i + 2) * 32, buffer,
842 FS_MEDIUM, leveldir[first_entry + i].color);
843 DrawGraphic(0, i + 2, GFX_KUGEL_BLAU);
847 DrawGraphic(0, 1, GFX_PFEIL_UP);
849 if (first_entry + num_page_entries < num_leveldirs)
850 DrawGraphic(0, MAX_LEVEL_SERIES_ON_SCREEN + 1, GFX_PFEIL_DOWN);
853 static void drawChooseLevelInfo(int leveldir_nr)
855 int x, last_redraw_mask = redraw_mask;
857 XFillRectangle(display, drawto, gc, SX + 32, SY + 32, SXSIZE - 32, 32);
860 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
861 leveldir[leveldir_nr].levels,
862 leveldir[leveldir_nr].readonly ? "readonly" : "writable");
864 DrawTextFCentered(40, FC_RED, "%3d levels (%s)",
865 leveldir[leveldir_nr].levels,
866 leveldir[leveldir_nr].class_desc);
869 /* let BackToFront() redraw only what is needed */
870 redraw_mask = last_redraw_mask | REDRAW_TILES;
871 for (x=0; x<SCR_FIELDX; x++)
875 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
877 static int choice = 3;
878 static int first_entry = -1;
879 static unsigned long choose_delay = 0;
880 static int redraw = TRUE;
881 int x = (mx + 32 - SX) / 32, y = (my + 32 - SY) / 32;
882 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
883 int num_page_entries;
885 if (num_leveldirs <= MAX_LEVEL_SERIES_ON_SCREEN)
886 num_page_entries = num_leveldirs;
888 num_page_entries = MAX_LEVEL_SERIES_ON_SCREEN - 1;
890 if (button == MB_MENU_INITIALIZE)
892 if (first_entry == -1)
894 first_entry = MAX(0, leveldir_nr - num_page_entries + 1);
895 choice = leveldir_nr - first_entry + 3;
898 drawChooseLevelList(first_entry, num_page_entries);
899 drawChooseLevelInfo(leveldir_nr);
905 DrawGraphic(0, choice - 1, GFX_KUGEL_ROT);
909 if (button == MB_MENU_INITIALIZE)
920 x = y = 0; /* no action */
922 if (ABS(dy) == SCR_FIELDY) /* handle XK_Page_Up, XK_Page_Down */
925 step = num_page_entries - 1;
927 y = (dy < 0 ? 2 : num_page_entries + 3);
931 if (x == 1 && y == 2)
933 if (first_entry > 0 &&
934 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
940 drawChooseLevelList(first_entry, num_page_entries);
941 drawChooseLevelInfo(first_entry + choice - 3);
942 DrawGraphic(0, choice - 1, GFX_KUGEL_ROT);
946 else if (x == 1 && y > num_page_entries + 2)
948 if (first_entry + num_page_entries < num_leveldirs &&
949 (dy || DelayReached(&choose_delay, GADGET_FRAME_DELAY)))
952 if (first_entry + num_page_entries > num_leveldirs)
953 first_entry = MAX(0, num_leveldirs - num_page_entries);
955 drawChooseLevelList(first_entry, num_page_entries);
956 drawChooseLevelInfo(first_entry + choice - 3);
957 DrawGraphic(0, choice - 1, GFX_KUGEL_ROT);
962 if (!mx && !my && !dx && !dy)
968 if (x == 1 && y >= 3 && y <= num_page_entries + 2)
974 DrawGraphic(0, y - 1, GFX_KUGEL_ROT);
975 DrawGraphic(0, choice - 1, GFX_KUGEL_BLAU);
976 drawChooseLevelInfo(first_entry + y - 3);
982 leveldir_nr = first_entry + y - 3;
983 LoadLevelSetup_SeriesInfo(leveldir_nr);
985 SaveLevelSetup_LastSeries();
986 SaveLevelSetup_SeriesInfo(leveldir_nr);
989 game_status = MAINMENU;
997 if (game_status == CHOOSELEVEL)
1001 void DrawHallOfFame(int highlight_position)
1004 CloseDoor(DOOR_CLOSE_2);
1006 if (highlight_position < 0)
1007 LoadScore(level_nr);
1011 HandleHallOfFame(highlight_position,0, 0,0, MB_MENU_INITIALIZE);
1012 PlaySound(SND_HALLOFFAME);
1015 static void drawHallOfFameList(int first_entry, int highlight_position)
1020 DrawText(SX + 80, SY + 8, "Hall Of Fame", FS_BIG, FC_YELLOW);
1021 DrawTextFCentered(46, FC_RED, "HighScores of Level %d", level_nr);
1023 for(i=0; i<MAX_LEVEL_SERIES_ON_SCREEN; i++)
1025 int entry = first_entry + i;
1026 int color = (entry == highlight_position ? FC_RED : FC_GREEN);
1029 DrawText(SX, SY + 64 + i * 32, ".................", FS_BIG, color);
1030 DrawText(SX, SY + 64 + i * 32, highscore[i].Name, FS_BIG, color);
1031 DrawText(SX + 12 * 32, SY + 64 + i * 32,
1032 int2str(highscore[i].Score, 5), FS_BIG, color);
1034 DrawText(SX, SY + 64 + i * 32, "..................................",
1035 FS_MEDIUM, FC_YELLOW);
1036 DrawText(SX, SY + 64 + i * 32, int2str(entry + 1, 3),
1037 FS_MEDIUM, FC_YELLOW);
1038 DrawText(SX + 64, SY + 64 + i * 32, highscore[entry].Name, FS_BIG, color);
1039 DrawText(SX + 14 * 32 + 16, SY + 64 + i * 32,
1040 int2str(highscore[entry].Score, 5), FS_MEDIUM, color);
1045 void HandleHallOfFame(int mx, int my, int dx, int dy, int button)
1047 static int first_entry = 0;
1048 static int highlight_position = 0;
1049 int step = (button == 1 ? 1 : button == 2 ? 5 : 10);
1050 int button_released = !button;
1052 if (button == MB_MENU_INITIALIZE)
1055 highlight_position = mx;
1056 drawHallOfFameList(first_entry, highlight_position);
1060 if (ABS(dy) == SCR_FIELDY) /* handle XK_Page_Up, XK_Page_Down */
1061 step = MAX_LEVEL_SERIES_ON_SCREEN - 1;
1065 if (first_entry > 0)
1067 first_entry -= step;
1068 if (first_entry < 0)
1071 drawHallOfFameList(first_entry, highlight_position);
1077 if (first_entry + MAX_LEVEL_SERIES_ON_SCREEN < MAX_SCORE_ENTRIES)
1079 first_entry += step;
1080 if (first_entry + MAX_LEVEL_SERIES_ON_SCREEN > MAX_SCORE_ENTRIES)
1081 first_entry = MAX(0, MAX_SCORE_ENTRIES - MAX_LEVEL_SERIES_ON_SCREEN);
1083 drawHallOfFameList(first_entry, highlight_position);
1088 if (button_released)
1090 FadeSound(SND_HALLOFFAME);
1091 game_status = MAINMENU;
1097 if (game_status == HALLOFFAME)
1101 void DrawSetupScreen()
1110 { &setup.sound, "Sound:", },
1111 { &setup.sound_loops, " Sound Loops:" },
1112 { &setup.sound_music, " Game Music:" },
1114 { &setup.toons, "Toons:" },
1115 { &setup.double_buffering, "Buffered gfx:" },
1117 { &setup.scroll_delay, "Scroll Delay:" },
1118 { &setup.soft_scrolling, "Soft Scroll.:" },
1119 { &setup.fading, "Fading:" },
1120 { &setup.quick_doors, "Quick Doors:" },
1121 { &setup.autorecord, "Auto-Record:" },
1122 { &setup.team_mode, "Team-Mode:" },
1123 { &setup.handicap, "Handicap:" },
1124 { &setup.time_limit, "Timelimit:" },
1125 { NULL, "Input Devices" },
1128 { NULL, "Save and exit" }
1132 CloseDoor(DOOR_CLOSE_2);
1135 DrawText(SX + 16, SY + 16, "SETUP",FS_BIG,FC_YELLOW);
1137 for(i=SETUP_SCREEN_POS_START;i<=SETUP_SCREEN_POS_END;i++)
1139 int base = i - SETUP_SCREEN_POS_START;
1141 if (!(i >= SETUP_SCREEN_POS_EMPTY1 && i <= SETUP_SCREEN_POS_EMPTY2))
1143 DrawGraphic(0,i,GFX_KUGEL_BLAU);
1144 DrawText(SX+32,SY+i*32, setup_info[base].text, FS_BIG,FC_GREEN);
1147 if (setup_info[base].value)
1149 int setting_value = *setup_info[base].value;
1151 DrawText(SX+14*32, SY+i*32, (setting_value ? "on" : "off"),
1152 FS_BIG, (setting_value ? FC_YELLOW : FC_BLUE));
1158 HandleSetupScreen(0,0,0,0,MB_MENU_INITIALIZE);
1161 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
1163 static int choice = 3;
1164 static int redraw = TRUE;
1165 int x = (mx+32-SX)/32, y = (my+32-SY)/32;
1166 int pos_start = SETUP_SCREEN_POS_START + 1;
1167 int pos_empty1 = SETUP_SCREEN_POS_EMPTY1 + 1;
1168 int pos_empty2 = SETUP_SCREEN_POS_EMPTY2 + 1;
1169 int pos_end = SETUP_SCREEN_POS_END + 1;
1171 if (button == MB_MENU_INITIALIZE)
1176 DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
1180 if (button == MB_MENU_INITIALIZE)
1193 if (y >= pos_empty1 && y <= pos_empty2)
1194 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1198 else if (y > pos_end)
1202 if (!mx && !my && !dx && !dy)
1208 if (x==1 && y >= pos_start && y <= pos_end &&
1209 !(y >= pos_empty1 && y <= pos_empty2))
1215 DrawGraphic(0,y-1,GFX_KUGEL_ROT);
1216 DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
1224 if (y==3 && sound_status==SOUND_AVAILABLE)
1228 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1229 DrawText(SX+14*32, SY+(yy+1)*32,"off",FS_BIG,FC_BLUE);
1230 DrawText(SX+14*32, SY+(yy+2)*32,"off",FS_BIG,FC_BLUE);
1231 setup.sound_loops = FALSE;
1232 setup.sound_music = FALSE;
1235 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1236 setup.sound = !setup.sound;
1238 else if (y==4 && sound_loops_allowed)
1240 if (setup.sound_loops)
1241 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1244 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1245 DrawText(SX+14*32, SY+(yy-1)*32,"on ",FS_BIG,FC_YELLOW);
1248 setup.sound_loops = !setup.sound_loops;
1250 else if (y==5 && sound_loops_allowed)
1252 if (setup.sound_music)
1253 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1256 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1257 DrawText(SX+14*32, SY+(yy-2)*32,"on ",FS_BIG,FC_YELLOW);
1260 setup.sound_music = !setup.sound_music;
1267 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1269 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1270 setup.toons = !setup.toons;
1275 if (setup.double_buffering)
1276 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1278 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1279 setup.double_buffering = !setup.double_buffering;
1280 setup.direct_draw = !setup.double_buffering;
1282 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1283 setup.double_buffering = TRUE;
1284 setup.direct_draw = !setup.double_buffering;
1291 if (setup.scroll_delay)
1292 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1294 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1295 setup.scroll_delay = !setup.scroll_delay;
1299 if (setup.soft_scrolling)
1300 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1302 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1303 setup.soft_scrolling = !setup.soft_scrolling;
1308 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1310 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1311 setup.fading = !setup.fading;
1315 if (setup.quick_doors)
1316 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1318 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1319 setup.quick_doors = !setup.quick_doors;
1323 if (setup.autorecord)
1324 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1326 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1327 setup.autorecord = !setup.autorecord;
1331 if (setup.team_mode)
1332 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1334 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1335 setup.team_mode = !setup.team_mode;
1340 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1342 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1343 setup.handicap = !setup.handicap;
1347 if (setup.time_limit)
1348 DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1350 DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1351 setup.time_limit = !setup.time_limit;
1355 game_status = SETUPINPUT;
1356 DrawSetupInputScreen();
1359 else if (y==pos_end-1 || y==pos_end)
1370 save_joystick_data(JOYSTICK_FILENAME);
1376 game_status = MAINMENU;
1384 if (game_status==SETUP)
1388 void DrawSetupInputScreen()
1391 DrawText(SX+16, SY+16, "SETUP INPUT", FS_BIG, FC_YELLOW);
1393 DrawGraphic(0, 2, GFX_KUGEL_BLAU);
1394 DrawGraphic(0, 3, GFX_KUGEL_BLAU);
1395 DrawGraphic(0, 4, GFX_KUGEL_BLAU);
1396 DrawGraphic(0, 15, GFX_KUGEL_BLAU);
1397 DrawGraphic(10, 2, GFX_PFEIL_LEFT);
1398 DrawGraphic(12, 2, GFX_PFEIL_RIGHT);
1400 DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
1401 DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
1402 DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
1404 DrawTextFCentered(SYSIZE - 20, FC_BLUE,
1405 "Joysticks deactivated on this screen");
1407 HandleSetupInputScreen(0,0, 0,0, MB_MENU_INITIALIZE);
1412 static void setJoystickDeviceToNr(char *device_name, int device_nr)
1414 if (device_name == NULL)
1417 if (device_nr < 0 || device_nr >= MAX_PLAYERS)
1420 if (strlen(device_name) > 1)
1422 char c1 = device_name[strlen(device_name) - 1];
1423 char c2 = device_name[strlen(device_name) - 2];
1425 if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
1426 device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
1429 strncpy(device_name, joystick_device_name[device_nr], strlen(device_name));
1432 static void drawPlayerSetupInputInfo(int player_nr)
1435 static struct SetupKeyboardInfo custom_key;
1442 { &custom_key.left, "Joystick Left" },
1443 { &custom_key.right, "Joystick Right" },
1444 { &custom_key.up, "Joystick Up" },
1445 { &custom_key.down, "Joystick Down" },
1446 { &custom_key.snap, "Button 1" },
1447 { &custom_key.bomb, "Button 2" }
1449 static char *joystick_name[MAX_PLAYERS] =
1457 custom_key = setup.input[player_nr].key;
1459 DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
1460 DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
1462 if (setup.input[player_nr].use_joystick)
1464 char *device_name = setup.input[player_nr].joy.device_name;
1466 DrawText(SX+8*32, SY+3*32,
1467 joystick_name[getJoystickNrFromDeviceName(device_name)],
1469 DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
1473 DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
1474 DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
1477 DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
1478 DrawGraphic(1, 6, GFX_PFEIL_LEFT);
1479 DrawGraphic(1, 7, GFX_PFEIL_RIGHT);
1480 DrawGraphic(1, 8, GFX_PFEIL_UP);
1481 DrawGraphic(1, 9, GFX_PFEIL_DOWN);
1482 DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
1483 DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
1484 DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
1485 DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
1486 DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
1487 DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
1491 int ypos = 6 + i + (i > 3 ? i-3 : 0);
1493 DrawText(SX + 3*32, SY + ypos*32,
1494 " ", FS_BIG, FC_YELLOW);
1495 DrawText(SX + 3*32, SY + ypos*32,
1496 (setup.input[player_nr].use_joystick ?
1498 getKeyNameFromKeySym(*custom[i].keysym)),
1503 void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
1505 static int choice = 3;
1506 static int player_nr = 0;
1507 static int redraw = TRUE;
1508 int x = (mx+32-SX)/32, y = (my+32-SY)/32;
1509 int pos_start = SETUPINPUT_SCREEN_POS_START + 1;
1510 int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1 + 1;
1511 int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2 + 1;
1512 int pos_end = SETUPINPUT_SCREEN_POS_END + 1;
1514 if (button == MB_MENU_INITIALIZE)
1516 drawPlayerSetupInputInfo(player_nr);
1522 DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
1526 if (button == MB_MENU_INITIALIZE)
1531 if (dx && choice == 3)
1533 x = (dx < 0 ? 11 : 13);
1536 else if (dx && choice == 4)
1538 button = MB_MENU_CHOICE;
1550 if (y >= pos_empty1 && y <= pos_empty2)
1551 y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
1555 else if (y > pos_end)
1559 if (!mx && !my && !dx && !dy)
1565 if (y == 3 && ((x == 1 && !button) || ((x == 11 || x == 13) && button)))
1567 static unsigned long delay = 0;
1569 if (!DelayReached(&delay, GADGET_FRAME_DELAY))
1572 player_nr = (player_nr + (x == 11 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
1574 drawPlayerSetupInputInfo(player_nr);
1576 else if (x==1 && y >= pos_start && y <= pos_end &&
1577 !(y >= pos_empty1 && y <= pos_empty2))
1583 DrawGraphic(0, y-1, GFX_KUGEL_ROT);
1584 DrawGraphic(0, choice-1, GFX_KUGEL_BLAU);
1592 char *device_name = setup.input[player_nr].joy.device_name;
1594 if (!setup.input[player_nr].use_joystick)
1596 int new_device_nr = (dx >= 0 ? 0 : MAX_PLAYERS - 1);
1598 setJoystickDeviceToNr(device_name, new_device_nr);
1599 setup.input[player_nr].use_joystick = TRUE;
1603 int device_nr = getJoystickNrFromDeviceName(device_name);
1604 int new_device_nr = device_nr + (dx >= 0 ? +1 : -1);
1606 if (new_device_nr < 0 || new_device_nr >= MAX_PLAYERS)
1607 setup.input[player_nr].use_joystick = FALSE;
1609 setJoystickDeviceToNr(device_name, new_device_nr);
1619 int one_joystick_nr = (dx >= 0 ? 0 : 1);
1620 int the_other_joystick_nr = (dx >= 0 ? 1 : 0);
1622 if (setup.input[player_nr].use_joystick)
1624 if (setup.input[player_nr].joystick_nr == one_joystick_nr)
1625 setup.input[player_nr].joystick_nr = the_other_joystick_nr;
1627 setup.input[player_nr].use_joystick = FALSE;
1631 setup.input[player_nr].use_joystick = TRUE;
1632 setup.input[player_nr].joystick_nr = one_joystick_nr;
1636 drawPlayerSetupInputInfo(player_nr);
1640 if (setup.input[player_nr].use_joystick)
1643 game_status = CALIBRATION;
1644 CalibrateJoystick(player_nr);
1645 game_status = SETUPINPUT;
1648 CustomizeKeyboard(player_nr);
1652 else if (y == pos_end)
1656 game_status = SETUP;
1666 if (game_status == SETUPINPUT)
1670 void CustomizeKeyboard(int player_nr)
1674 boolean finished = FALSE;
1675 static struct SetupKeyboardInfo custom_key;
1680 } customize_step[] =
1682 { &custom_key.left, "Move Left" },
1683 { &custom_key.right, "Move Right" },
1684 { &custom_key.up, "Move Up" },
1685 { &custom_key.down, "Move Down" },
1686 { &custom_key.snap, "Snap Field" },
1687 { &custom_key.bomb, "Place Bomb" }
1690 /* read existing key bindings from player setup */
1691 custom_key = setup.input[player_nr].key;
1694 DrawText(SX + 16, SY + 16, "Keyboard Input", FS_BIG, FC_YELLOW);
1700 DrawText(SX, SY + (2+2*step_nr)*32,
1701 customize_step[step_nr].text, FS_BIG, FC_RED);
1702 DrawText(SX, SY + (2+2*step_nr+1)*32,
1703 "Key:", FS_BIG, FC_RED);
1704 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1705 getKeyNameFromKeySym(*customize_step[step_nr].keysym),
1710 if (XPending(display)) /* got event from X server */
1714 XNextEvent(display, &event);
1720 KeySym key = XLookupKeysym((XKeyEvent *)&event,
1721 ((XKeyEvent *)&event)->state);
1723 if (key == XK_Escape || (key == XK_Return && step_nr == 6))
1729 /* press 'Enter' to keep the existing key binding */
1730 if (key == XK_Return || step_nr == 6)
1731 key = *customize_step[step_nr].keysym;
1733 /* check if key already used */
1734 for (i=0; i<step_nr; i++)
1735 if (*customize_step[i].keysym == key)
1740 /* got new key binding */
1741 *customize_step[step_nr].keysym = key;
1742 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1743 " ", FS_BIG, FC_YELLOW);
1744 DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
1745 getKeyNameFromKeySym(key), FS_BIG, FC_YELLOW);
1748 /* un-highlight last query */
1749 DrawText(SX, SY+(2+2*(step_nr-1))*32,
1750 customize_step[step_nr-1].text, FS_BIG, FC_GREEN);
1751 DrawText(SX, SY+(2+2*(step_nr-1)+1)*32,
1752 "Key:", FS_BIG, FC_GREEN);
1754 /* press 'Enter' to leave */
1757 DrawText(SX + 16, SY + 15*32+16,
1758 "Press Enter", FS_BIG, FC_YELLOW);
1762 /* query next key binding */
1763 DrawText(SX, SY+(2+2*step_nr)*32,
1764 customize_step[step_nr].text, FS_BIG, FC_RED);
1765 DrawText(SX, SY+(2+2*step_nr+1)*32,
1766 "Key:", FS_BIG, FC_RED);
1767 DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
1768 getKeyNameFromKeySym(*customize_step[step_nr].keysym),
1774 key_joystick_mapping = 0;
1778 HandleOtherEvents(&event);
1786 /* don't eat all CPU time */
1790 /* write new key bindings back to player setup */
1791 setup.input[player_nr].key = custom_key;
1794 DrawSetupInputScreen();
1797 void CalibrateJoystick(int player_nr)
1800 struct joystick joy_ctrl;
1802 struct joystick_control
1811 int new_joystick_xleft = 128, new_joystick_xright = 128;
1812 int new_joystick_yupper = 128, new_joystick_ylower = 128;
1813 int new_joystick_xmiddle, new_joystick_ymiddle;
1815 int calibration_step = 1;
1818 int joystick_fd = stored_player[player_nr].joystick_fd;
1819 int x, y, last_x, last_y, xpos = 8, ypos = 3;
1820 boolean check[3][3];
1821 int check_remaining;
1825 if (joystick_status == JOYSTICK_OFF ||
1827 !setup.input[player_nr].use_joystick)
1833 DrawText(SX, SY + 6*32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
1834 DrawText(SX, SY + 7*32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
1835 DrawText(SX + 16, SY + 9*32, " IF ALL BALLS ", FS_BIG, FC_YELLOW);
1836 DrawText(SX, SY + 10*32, " ARE YELLOW, ", FS_BIG, FC_YELLOW);
1837 DrawText(SX, SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
1838 check_remaining = 3 * 3;
1840 DrawText(SX, SY + 7*32, " MOVE JOYSTICK ", FS_BIG, FC_YELLOW);
1841 DrawText(SX + 16, SY + 8*32, " TO ", FS_BIG, FC_YELLOW);
1842 DrawText(SX, SY + 9*32, " CENTER POSITION ", FS_BIG, FC_YELLOW);
1843 DrawText(SX, SY + 10*32, " AND ", FS_BIG, FC_YELLOW);
1844 DrawText(SX, SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
1845 check_remaining = 0;
1852 check[x][y] = FALSE;
1853 DrawGraphic(xpos + x - 1, ypos + y - 1, GFX_KUGEL_BLAU);
1857 joy_value = Joystick(player_nr);
1858 last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
1859 last_y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
1860 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
1865 joy_ctrl.b1 = joy_ctrl.b2 = 0;
1867 joy_ctrl.buttons = 0;
1870 while(Joystick(player_nr) & JOY_BUTTON);
1876 if (XPending(display)) /* got event from X server */
1880 XNextEvent(display, &event);
1885 switch(XLookupKeysym((XKeyEvent *)&event,
1886 ((XKeyEvent *)&event)->state))
1889 if (check_remaining == 0)
1903 key_joystick_mapping = 0;
1907 HandleOtherEvents(&event);
1913 if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1915 joystick_status = JOYSTICK_OFF;
1919 new_joystick_xleft = MIN(new_joystick_xleft, joy_ctrl.x);
1920 new_joystick_xright = MAX(new_joystick_xright, joy_ctrl.x);
1921 new_joystick_yupper = MIN(new_joystick_yupper, joy_ctrl.y);
1922 new_joystick_ylower = MAX(new_joystick_ylower, joy_ctrl.y);
1924 new_joystick_xmiddle =
1925 new_joystick_xleft + (new_joystick_xright - new_joystick_xleft) / 2;
1926 new_joystick_ymiddle =
1927 new_joystick_yupper + (new_joystick_ylower - new_joystick_yupper) / 2;
1929 setup.input[player_nr].joy.xleft = new_joystick_xleft;
1930 setup.input[player_nr].joy.yupper = new_joystick_yupper;
1931 setup.input[player_nr].joy.xright = new_joystick_xright;
1932 setup.input[player_nr].joy.ylower = new_joystick_ylower;
1933 setup.input[player_nr].joy.xmiddle = new_joystick_xmiddle;
1934 setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
1936 CheckJoystickData();
1939 joy_value = Joystick(player_nr);
1941 if (joy_value & JOY_BUTTON && check_remaining == 0)
1946 if (calibration_step == 1)
1951 else if (calibrate_joystick(joystick_fd) != 0)
1953 joystick_status = JOYSTICK_OFF;
1957 if (joy[joystick_fd].flags & JOYFLAG_CALIBRATE)
1962 DrawText(SX, SY + 7*32, " MOVE JOYSTICK ", FS_BIG, FC_YELLOW);
1963 DrawText(SX + 16, SY + 8*32, " TO ", FS_BIG, FC_YELLOW);
1965 if (calibration_step == 2)
1966 DrawText(SX + 16, SY + 9*32," THE UPPER LEFT ", FS_BIG, FC_YELLOW);
1968 DrawText(SX, SY + 9*32," THE LOWER RIGHT ", FS_BIG, FC_YELLOW);
1970 DrawText(SX, SY + 10*32, " AND ", FS_BIG, FC_YELLOW);
1971 DrawText(SX, SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
1975 while(Joystick(player_nr) & JOY_BUTTON)
1981 x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
1982 y = (joy_value & JOY_UP ? -1 : joy_value & JOY_DOWN ? +1 : 0);
1984 if (x != last_x || y != last_y)
1987 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
1989 DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_BLAU);
1991 DrawGraphic(xpos + x, ypos + y, GFX_KUGEL_ROT);
1996 if (check_remaining > 0 && !check[x+1][y+1])
1998 check[x+1][y+1] = TRUE;
2003 printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
2004 setup.input[player_nr].joy.xleft,
2005 setup.input[player_nr].joy.xmiddle,
2006 setup.input[player_nr].joy.xright);
2007 printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
2008 setup.input[player_nr].joy.yupper,
2009 setup.input[player_nr].joy.ymiddle,
2010 setup.input[player_nr].joy.ylower);
2018 /* don't eat all CPU time */
2024 DrawSetupInputScreen();
2025 while(Joystick(player_nr) & JOY_BUTTON);
2031 DrawText(SX + 16, SY + 6*32, " JOYSTICK NOT ", FS_BIG, FC_YELLOW);
2032 DrawText(SX, SY + 7*32, " AVAILABLE ", FS_BIG, FC_YELLOW);
2035 DrawSetupInputScreen();
2038 void HandleGameActions()
2040 if (game_status != PLAYING)
2043 if (local_player->LevelSolved)
2046 if (AllPlayersGone && !TAPE_IS_STOPPED(tape))