3a8f0bb5e39ff0138a79a048e18e26d2ba3c4505
[rocksndiamonds.git] / src / screens.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
6 *        33659 Bielefeld-Senne                             *
7 *        Telefon: (0521) 493245                            *
8 *        eMail: aeglos@valinor.owl.de                      *
9 *               aeglos@uni-paderborn.de                    *
10 *               q99492@pbhrzx.uni-paderborn.de             *
11 *----------------------------------------------------------*
12 *  screens.c                                               *
13 ***********************************************************/
14
15 #include "screens.h"
16 #include "events.h"
17 #include "sound.h"
18 #include "game.h"
19 #include "tools.h"
20 #include "editor.h"
21 #include "misc.h"
22 #include "files.h"
23 #include "buttons.h"
24 #include "tape.h"
25
26 void DrawHeadline()
27 {
28   int x1 = SX+(SXSIZE - strlen(GAMETITLE_STRING) * FONT1_XSIZE) / 2;
29   int y1 = SY+8;
30   int x2 = SX+(SXSIZE - strlen(COPYRIGHT_STRING) * FONT2_XSIZE) / 2;
31   int y2 = SY+46;
32
33   DrawText(x1,y1, GAMETITLE_STRING, FS_BIG,FC_YELLOW);
34   DrawText(x2,y2, COPYRIGHT_STRING, FS_SMALL,FC_RED);
35 }
36
37 void DrawMainMenu()
38 {
39   int i;
40
41   FadeSounds();
42   GetPlayerConfig();
43   LoadLevel(level_nr);
44
45   ClearWindow();
46   DrawHeadline();
47   DrawText(SX+32, SY+64, "Name:",FS_BIG,FC_GREEN);
48   DrawText(SX+192,SY+64, player.alias_name,FS_BIG,FC_RED);
49   DrawText(SX+32, SY+96, "Level:",FS_BIG,FC_GREEN);
50   DrawText(SX+352,SY+96, int2str(level_nr,3),FS_BIG,
51            (level_nr<leveldir[leveldir_nr].levels ? FC_RED : FC_YELLOW));
52   DrawText(SX+32, SY+128,"Hall Of Fame",FS_BIG,FC_GREEN);
53   DrawText(SX+32, SY+160,"Level Creator",FS_BIG,FC_GREEN);
54   DrawText(SY+32, SY+192,"Info Screen",FS_BIG,FC_GREEN);
55   DrawText(SX+32, SY+224,"Start Game",FS_BIG,FC_GREEN);
56   DrawText(SX+32, SY+256,"Setup",FS_BIG,FC_GREEN);
57   DrawText(SX+32, SY+288,"Quit",FS_BIG,FC_GREEN);
58
59   DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS);
60
61   for(i=2;i<10;i++)
62     DrawGraphic(0,i,GFX_KUGEL_BLAU);
63   DrawGraphic(10,3,GFX_PFEIL_L);
64   DrawGraphic(14,3,GFX_PFEIL_R);
65
66   DrawText(SX+54+16,SY+326,"A Game by Artsoft Development",FS_SMALL,FC_BLUE);
67   DrawText(SX+40+16,SY+344,"Graphics: Deluxe Paint IV Amiga",
68            FS_SMALL,FC_BLUE);
69   DrawText(SX+60+16,SY+362,"Sounds: AudioMaster IV Amiga",
70            FS_SMALL,FC_BLUE);
71
72   FadeToFront();
73   InitAnimation();
74   HandleMainMenu(0,0,0,0,MB_MENU_MARK);
75
76   TapeStop();
77   if (TAPE_IS_EMPTY(tape))
78     LoadLevelTape(level_nr);
79   DrawCompleteVideoDisplay();
80
81   OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2);
82
83   XAutoRepeatOn(display);
84 }
85
86 void HandleMainMenu(int mx, int my, int dx, int dy, int button)
87 {
88   static int choice = 3;
89   static int redraw = TRUE;
90   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
91
92   if (redraw || (!mx && !my && !dx && !dy))
93   {
94     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
95     redraw = FALSE;
96   }
97
98   if (dx || dy)
99   {
100     if (dx && choice==4)
101     {
102       x = (dx<0 ? 11 : 15);
103       y = 4;
104     }
105     else if (dy)
106     {
107       x = 1;
108       y = choice+dy;
109     }
110     else
111       x = y = 0;
112
113     if (y<3)
114       y = 3;
115     else if (y>10)
116       y = 10;
117   }
118
119   if (!mx && !my && !dx && !dy)
120   {
121     x = 1;
122     y = choice;
123   }
124
125   if (y==4 && ((x==11 && level_nr>0) ||
126                (x==15 && level_nr<leveldir[leveldir_nr].levels)) &&
127       button)
128   {
129     static long level_delay = 0;
130     int step = (button==1 ? 1 : button==2 ? 5 : 10);
131     int new_level_nr, old_level_nr = level_nr;
132
133     new_level_nr = level_nr + (x==11 ? -step : +step);
134     if (new_level_nr<0)
135       new_level_nr = 0;
136     if (new_level_nr>leveldir[leveldir_nr].levels-1)
137       new_level_nr = leveldir[leveldir_nr].levels-1;
138
139     if (old_level_nr==new_level_nr || !DelayReached(&level_delay,15))
140       goto out;
141
142     level_nr = new_level_nr;
143
144     if (level_nr>player.handicap)
145       level_nr = player.handicap;
146
147     DrawTextExt(drawto,gc,SX+352,SY+96, int2str(level_nr,3), FS_BIG,FC_RED);
148     DrawTextExt(window,gc,SX+352,SY+96, int2str(level_nr,3), FS_BIG,FC_RED);
149
150     LoadLevel(level_nr);
151     DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS);
152
153     TapeErase();
154     LoadLevelTape(level_nr);
155     DrawCompleteVideoDisplay();
156
157     /* needed because DrawMicroLevel() takes some time */
158     BackToFront();
159     XSync(display,FALSE);
160     DelayReached(&level_delay,0);       /* reset delay counter */
161   }
162   else if (x==1 && y>=3 && y<=10)
163   {
164     if (button)
165     {
166       if (y!=choice)
167       {
168         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
169         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
170       }
171       choice = y;
172     }
173     else
174     {
175       if (y==3)
176       {
177         game_status = TYPENAME;
178         HandleTypeName(strlen(player.alias_name),0);
179       }
180       else if (y==4)
181       {
182         if (num_leveldirs)
183         {
184           game_status = CHOOSELEVEL;
185           SavePlayerInfo(PLAYER_LEVEL);
186           DrawChooseLevel();
187         }
188       }
189       else if (y==5)
190       {
191         game_status = HALLOFFAME;
192         DrawHallOfFame(-1);
193       }
194       else if (y==6)
195       {
196         game_status = LEVELED;
197         if (leveldir[leveldir_nr].readonly)
198           AreYouSure("This level is read only !",AYS_CONFIRM);
199         DrawLevelEd();
200       }
201       else if (y==7)
202       {
203         game_status = HELPSCREEN;
204         DrawHelpScreen();
205       }
206       else if (y==8)
207       {
208         if (autorecord_on)
209           TapeStartRecording();
210
211         game_status = PLAYING;
212         InitGame();
213       }
214       else if (y==9)
215       {
216         game_status = SETUP;
217         DrawSetupScreen();
218       }
219       else if (y==10)
220       {
221         SavePlayerInfo(PLAYER_LEVEL);
222         if (AreYouSure("Do you really want to quit ?",AYS_ASK|AYS_STAY_CLOSED))
223           game_status = EXITGAME;
224       }
225
226       redraw = TRUE;
227     }
228   }
229   BackToFront();
230
231   out:
232
233   if (game_status==MAINMENU)
234     DoAnimation();
235 }
236
237 #define MAX_HELPSCREEN_ELS      10
238 #define HA_NEXT                 -999
239 #define HA_END                  -1000
240
241 static long helpscreen_state;
242 static int helpscreen_step[MAX_HELPSCREEN_ELS];
243 static int helpscreen_frame[MAX_HELPSCREEN_ELS];
244 static int helpscreen_delay[MAX_HELPSCREEN_ELS];
245 static int helpscreen_action[] =
246 {
247   GFX_SPIELFIGUR,1,100,                                         HA_NEXT,
248   GFX_ERDREICH,1,100,                                           HA_NEXT,
249   GFX_LEERRAUM,1,100,                                           HA_NEXT,
250   GFX_MORAST_LEER,1,100,                                        HA_NEXT,
251   GFX_BETON,1,100,                                              HA_NEXT,
252   GFX_MAUERWERK,1,100,                                          HA_NEXT,
253   GFX_MAUER_R1,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,
254   GFX_MAUER_L1,3,4, GFX_MAUERWERK,1,20, GFX_LEERRAUM,1,10,      HA_NEXT,
255   GFX_UNSICHTBAR,1,100,                                         HA_NEXT,
256   GFX_FELSBODEN,1,100,                                          HA_NEXT,
257   GFX_CHAR_A,30,3, GFX_CHAR_AUSRUF,32,3,                        HA_NEXT,
258   GFX_EDELSTEIN,2,5,                                            HA_NEXT,
259   GFX_DIAMANT,2,5,                                              HA_NEXT,
260   GFX_EDELSTEIN_BD,2,5,                                         HA_NEXT,
261   GFX_EDELSTEIN_GELB,2,5, GFX_EDELSTEIN_ROT,2,5,
262   GFX_EDELSTEIN_LILA,2,5,                                       HA_NEXT,
263   GFX_FELSBROCKEN,4,5,                                          HA_NEXT,
264   GFX_BOMBE,1,50, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10,         HA_NEXT,
265   GFX_KOKOSNUSS,1,50, GFX_CRACKINGNUT,3,1, GFX_EDELSTEIN,1,10,  HA_NEXT,
266   GFX_ERZ_EDEL,1,50, GFX_EXPLOSION,8,1, GFX_EDELSTEIN,1,10,     HA_NEXT,
267   GFX_ERZ_DIAM,1,50, GFX_EXPLOSION,8,1, GFX_DIAMANT,1,10,       HA_NEXT,
268   GFX_ERZ_EDEL_BD,1,50, GFX_EXPLOSION,8,1,GFX_EDELSTEIN_BD,1,10,HA_NEXT,
269   GFX_ERZ_EDEL_GELB,1,50, GFX_EXPLOSION,8,1,
270   GFX_EDELSTEIN_GELB,1,10, GFX_ERZ_EDEL_ROT,1,50,
271   GFX_EXPLOSION,8,1, GFX_EDELSTEIN_ROT,1,10,
272   GFX_ERZ_EDEL_LILA,1,50, GFX_EXPLOSION,8,1,
273   GFX_EDELSTEIN_LILA,1,10,                                      HA_NEXT,
274   GFX_GEBLUBBER,4,4,                                            HA_NEXT,
275   GFX_SCHLUESSEL1,4,33,                                         HA_NEXT,
276   GFX_PFORTE1,4,33,                                             HA_NEXT,
277   GFX_PFORTE1X,4,33,                                            HA_NEXT,
278   GFX_DYNAMIT_AUS,1,100,                                        HA_NEXT,
279   GFX_DYNAMIT,7,6, GFX_EXPLOSION,8,1, GFX_LEERRAUM,1,10,        HA_NEXT,
280   GFX_DYNABOMB+0,4,3, GFX_DYNABOMB+3,1,3, GFX_DYNABOMB+2,1,3,
281   GFX_DYNABOMB+1,1,3, GFX_DYNABOMB+0,1,3, GFX_EXPLOSION,8,1,
282   GFX_LEERRAUM,1,10,                                            HA_NEXT,
283   GFX_DYNABOMB_NR,1,100,                                        HA_NEXT,
284   GFX_DYNABOMB_SZ,1,100,                                        HA_NEXT,
285   GFX_FLIEGER+4,1,3, GFX_FLIEGER+0,1,3, GFX_FLIEGER+4,1,3,
286   GFX_FLIEGER+5,1,3, GFX_FLIEGER+1,1,3, GFX_FLIEGER+5,1,3,
287   GFX_FLIEGER+6,1,3, GFX_FLIEGER+2,1,3, GFX_FLIEGER+6,1,3,
288   GFX_FLIEGER+7,1,3, GFX_FLIEGER+3,1,3, GFX_FLIEGER+7,1,3,      HA_NEXT,
289   GFX_KAEFER+4,1,1, GFX_KAEFER+0,1,1, GFX_KAEFER+4,1,1,
290   GFX_KAEFER+5,1,1, GFX_KAEFER+1,1,1, GFX_KAEFER+5,1,1,
291   GFX_KAEFER+6,1,1, GFX_KAEFER+2,1,1, GFX_KAEFER+6,1,1,
292   GFX_KAEFER+7,1,1, GFX_KAEFER+3,1,1, GFX_KAEFER+7,1,1,         HA_NEXT,
293   GFX_BUTTERFLY,1,1, GFX_BUTTERFLY+1,1,1,                       HA_NEXT,
294   GFX_FIREFLY,1,1, GFX_FIREFLY+1,1,1,                           HA_NEXT,
295   GFX_PACMAN+0,1,3, GFX_PACMAN+4,1,2, GFX_PACMAN+0,1,3,
296   GFX_PACMAN+1,1,3, GFX_PACMAN+5,1,2, GFX_PACMAN+1,1,3,
297   GFX_PACMAN+2,1,3, GFX_PACMAN+6,1,2, GFX_PACMAN+2,1,3,
298   GFX_PACMAN+3,1,3, GFX_PACMAN+7,1,2, GFX_PACMAN+3,1,3,         HA_NEXT,
299   GFX_MAMPFER+0,4,0, GFX_MAMPFER+3,1,0, GFX_MAMPFER+2,1,0,
300   GFX_MAMPFER+1,1,0, GFX_MAMPFER+0,1,0,                         HA_NEXT,
301   GFX_MAMPFER2+0,4,0, GFX_MAMPFER2+3,1,0, GFX_MAMPFER2+2,1,0,
302   GFX_MAMPFER2+1,1,0, GFX_MAMPFER2+0,1,0,                       HA_NEXT,
303   GFX_ZOMBIE+0,4,0, GFX_ZOMBIE+3,1,0, GFX_ZOMBIE+2,1,0,
304   GFX_ZOMBIE+1,1,0, GFX_ZOMBIE+0,1,0,                           HA_NEXT,
305   GFX_ABLENK,4,1,                                               HA_NEXT,
306   GFX_BIRNE_AUS,1,33, GFX_BIRNE_EIN,1,33,                       HA_NEXT,
307   GFX_ZEIT_VOLL,1,33, GFX_ZEIT_LEER,1,33,                       HA_NEXT,
308   GFX_TROPFEN,1,33, GFX_AMOEBING,4,1, GFX_AMOEBE_LEBT,1,10,     HA_NEXT,
309   GFX_AMOEBE_TOT+2,2,50, GFX_AMOEBE_TOT,2,50,                   HA_NEXT,
310   GFX_AMOEBE_LEBT,4,40,                                         HA_NEXT,
311   GFX_AMOEBE_LEBT,1,10, GFX_AMOEBING,4,2,                       HA_NEXT,
312   GFX_AMOEBE_LEBT,1,33, GFX_AMOEBE_TOT,1,33, GFX_EXPLOSION,8,1,
313   GFX_DIAMANT,1,10,                                             HA_NEXT,
314   GFX_LIFE,1,100,                                               HA_NEXT,
315   GFX_LIFE_ASYNC,1,100,                                         HA_NEXT,
316   GFX_SIEB_LEER,4,2,                                            HA_NEXT,
317   GFX_SIEB2_LEER,4,2,                                           HA_NEXT,
318   GFX_AUSGANG_ZU,1,100, GFX_AUSGANG_ACT,4,2,
319   GFX_AUSGANG_AUF+0,4,1, GFX_AUSGANG_AUF+3,1,1,
320   GFX_AUSGANG_AUF+2,1,1, GFX_AUSGANG_AUF+1,1,1,                 HA_NEXT,
321   GFX_AUSGANG_AUF+0,4,1, GFX_AUSGANG_AUF+3,1,1,
322   GFX_AUSGANG_AUF+2,1,1, GFX_AUSGANG_AUF+1,1,1,                 HA_NEXT,
323   HA_END
324 };
325 static char *helpscreen_eltext[][2] =
326 {
327  {"THE HERO:",                          "(Is _this_ guy good old Rockford?)"},
328  {"Normal sand:",                       "You can dig through it"},
329  {"Empty field:",                       "You can walk through it"},
330  {"Quicksand: You cannot pass it,",     "but rocks can fall though it"},
331  {"Massive Wall:",                      "Nothing can go through it"},
332  {"Normal Wall: You can't go through",  "it, but you can bomb it away"},
333  {"Growing Wall: Grows to the left or", "right if there is an empty field"},
334  {"Invisible Wall: Behaves like normal","wall, but is invisible"},
335  {"Old Wall: Like normal wall, but",    "some things can fall down from it"},
336  {"Letter Wall: Looks like a letter,",  "behaves like a normal wall"},
337  {"Emerald: You must collect enough of","them to finish a level"},
338  {"Diamond: Counts as 3 emeralds, but", "can be destroyed by rocks"},
339  {"Diamond (BD style): Counts like one","emerald and behaves a bit different"},
340  {"Colorful Gems:",                     "Seem to behave like Emeralds"},
341  {"Rock: Smashes several things;",      "Can be moved by the player"},
342  {"Bomb: You can move it, but be",      "careful when dropping it"},
343  {"Nut: Throw a rock on it to open it;","Each nut contains an emerald"},
344  {"Wall with an emerald inside:",       "Bomb the wall away to get it"},
345  {"Wall with a diamond inside:",        "Bomb the wall away to get it"},
346  {"Wall with BD style diamond inside:", "Bomb the wall away to get it"},
347  {"Wall with colorful gem inside:",     "Bomb the wall away to get it"},
348  {"Acid: Things that fall in are gone", "forever (including our hero)"},
349  {"Key: Opens the door that has the",   "same color (red/yellow/green/blue)"},
350  {"Door: Can be opened by the key",     "with the same color"},
351  {"Door: You have to find out the",     "right color of the key for it"},
352  {"Dynamite: Collect it and use it to", "destroy walls or kill enemies"},
353  {"Dynamite: This one explodes after",  "a few seconds"},
354  {"Dyna Bomb: Explodes in 4 directions","with variable explosion size"},
355  {"Dyna Bomb: Increases the number of", "dyna bombs available at a time"},
356  {"Dyna Bomb: Increases the size of",   "explosion of dyna bombs"},
357  {"Spaceship: Moves at the left side",  "of walls; don't touch it!"},
358  {"Bug: Moves at the right side",       "of walls; don't touch it!"},
359  {"Butterfly: Moves at the right side", "of walls; don't touch it!"},
360  {"Firefly: Moves at the left side",    "of walls; don't touch it!"},
361  {"Pacman: Eats the amoeba and you,",   "if you're not careful"},
362  {"Cruncher: Eats diamonds and you,",   "if you're not careful"},
363  {"Cruncher (BD style):",               "Eats almost everything"},
364  {"Robot: Tries to kill the player",    ""},
365  {"Magic Wheel: Touch it to get rid of","the robots for some seconds"},
366  {"Light Bulb: All of them must be",    "switched on to finish a level"},
367  {"Extra Time Orb: Adds some seconds",  "to the time available for the level"},
368  {"Amoeba Drop: Grows to an amoeba on", "the ground - don't touch it"},
369  {"Dead Amoeba: Does not grow, but",    "can still kill bugs and spaceships"},
370  {"Normal Amoeba: Grows through empty", "fields, sand and quicksand"},
371  {"Dropping Amoeba: This one makes",    "drops that grow to a new amoeba"},
372  {"Living Amoeba (BD style): Contains", "other element, when surrounded"},
373  {"Game Of Life: Behaves like the well","known 'Game Of Life' (2333 style)"},
374  {"Biomaze: A bit like the 'Game Of",   "Life', but builds crazy mazes"},
375  {"Magic Wall: Changes rocks, emeralds","and diamonds when they pass it"},
376  {"Magic Wall (BD style):",             "Changes rocks and BD style diamonds"},
377  {"Exit door: Opens if you have enough","emeralds to finish the level"},
378  {"Open exit door: Enter here to leave","the level and exit the actual game"},
379 };
380 static int num_helpscreen_els = sizeof(helpscreen_eltext)/(2*sizeof(char *));
381
382 static char *helpscreen_music[][3] =
383 {
384   { "Alchemy",                  "Ian Boddy",            "Drive" },
385   { "The Chase",                "Propaganda",           "A Secret Wish" },
386   { "Network 23",               "Tangerine Dream",      "Exit" },
387   { "Czardasz",                 "Robert Pieculewicz",   "Czardasz" },
388   { "21st Century Common Man",  "Tangerine Dream",      "Tyger" },
389   { "Voyager",                  "The Alan Parsons Project","Pyramid" },
390   { "Twilight Painter",         "Tangerine Dream",      "Heartbreakers" }
391 };
392 static int helpscreen_musicpos;
393
394 void DrawHelpScreenElAction(int start)
395 {
396   int i = 0, j = 0;
397   int frame, delay, graphic;
398   int xstart = SX+16, ystart = SY+64+2*32, ystep = TILEY+4;
399
400   while(helpscreen_action[j] != HA_END)
401   {
402     if (i>=start+MAX_HELPSCREEN_ELS || i>=num_helpscreen_els)
403       break;
404     else if (i<start || helpscreen_delay[i-start])
405     {
406       if (i>=start && helpscreen_delay[i-start])
407         helpscreen_delay[i-start]--;
408
409       while(helpscreen_action[j] != HA_NEXT)
410         j++;
411       j++;
412       i++;
413       continue;
414     }
415
416     j += 3*helpscreen_step[i-start];
417     graphic = helpscreen_action[j++];
418
419     if (helpscreen_frame[i-start])
420     {
421       frame = helpscreen_action[j++] - helpscreen_frame[i-start];
422       helpscreen_frame[i-start]--;
423     }
424     else
425     {
426       frame = 0;
427       helpscreen_frame[i-start] = helpscreen_action[j++]-1;
428     }
429
430     delay = helpscreen_action[j++];
431     helpscreen_delay[i-start] = delay;
432
433     if (helpscreen_action[j] == HA_NEXT)
434     {
435       if (!helpscreen_frame[i-start])
436         helpscreen_step[i-start] = 0;
437     }
438     else
439     {
440       if (!helpscreen_frame[i-start])
441         helpscreen_step[i-start]++;
442       while(helpscreen_action[j] != HA_NEXT)
443         j++;
444     }
445     j++;
446
447     DrawGraphicExtHiRes(drawto,gc,xstart,ystart+(i-start)*ystep,
448                         graphic+frame);
449     i++;
450   }
451
452   redraw_tiles += 28;
453   for(i=2;i<16;i++)
454     redraw[0][i] = redraw[1][i] = TRUE;
455   redraw_mask |= REDRAW_TILES;
456 }
457
458 void DrawHelpScreenElText(int start)
459 {
460   int i;
461   int xstart = SX+56, ystart = SY+65+2*32, ystep = TILEY+4;
462   char text[FULL_SXSIZE/FONT2_XSIZE+10];
463
464   ClearWindow();
465   DrawHeadline();
466
467   sprintf(text,"The game elements:");
468   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
469            text,FS_SMALL,FC_GREEN);
470
471   for(i=start;i<start+MAX_HELPSCREEN_ELS && i<num_helpscreen_els;i++)
472   {
473     DrawText(xstart,ystart+(i-start)*ystep+(*helpscreen_eltext[i][1] ? 0 : 8),
474              helpscreen_eltext[i][0],FS_SMALL,FC_YELLOW);
475     DrawText(xstart,ystart+(i-start)*ystep+16,
476              helpscreen_eltext[i][1],FS_SMALL,FC_YELLOW);
477   }
478
479   sprintf(text,"Press any key or button for next page");
480   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
481            text,FS_SMALL,FC_BLUE);
482 }
483
484 void DrawHelpScreenMusicText(int num)
485 {
486   int ystart = 150, ystep = 30;
487   char text[FULL_SXSIZE/FONT2_XSIZE+10];
488
489   FadeSounds();
490   ClearWindow();
491   DrawHeadline();
492
493   sprintf(text,"The game background music loops:");
494   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
495            text,FS_SMALL,FC_GREEN);
496
497   sprintf(text,"Excerpt from");
498   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+0*ystep,
499            text,FS_SMALL,FC_YELLOW);
500   sprintf(text,"%c%s%c",'\"',helpscreen_music[num][0],'\"');
501   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+1*ystep,
502            text,FS_SMALL,FC_RED);
503   sprintf(text,"by");
504   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+2*ystep,
505            text,FS_SMALL,FC_YELLOW);
506   sprintf(text,"%s",helpscreen_music[num][1]);
507   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+3*ystep,
508            text,FS_SMALL,FC_RED);
509   sprintf(text,"from the album");
510   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep,
511            text,FS_SMALL,FC_YELLOW);
512   sprintf(text,"%c%s%c",'\"',helpscreen_music[num][2],'\"');
513   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+5*ystep,
514            text,FS_SMALL,FC_RED);
515
516   sprintf(text,"Press any key or button for next page");
517   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
518            text,FS_SMALL,FC_BLUE);
519
520   PlaySoundLoop(background_loop[num]);
521 }
522
523 void DrawHelpScreenCreditsText()
524 {
525   int ystart = 150, ystep = 30;
526   char text[FULL_SXSIZE/FONT2_XSIZE+10];
527
528   FadeSounds();
529   ClearWindow();
530   DrawHeadline();
531
532   sprintf(text,"Program information:");
533   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+100,
534            text,FS_SMALL,FC_GREEN);
535
536   sprintf(text,"This game is Freeware!");
537   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+0*ystep,
538            text,FS_SMALL,FC_YELLOW);
539   sprintf(text,"If you like it, send e-mail to:");
540   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+1*ystep,
541            text,FS_SMALL,FC_YELLOW);
542   sprintf(text,"aeglos@valinor.owl.de");
543   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+2*ystep,
544            text,FS_SMALL,FC_RED);
545   sprintf(text,"or SnailMail to:");
546   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+3*ystep,
547            text,FS_SMALL,FC_YELLOW);
548   sprintf(text,"Holger Schemel");
549   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep,
550            text,FS_SMALL,FC_RED);
551   sprintf(text,"Sennehof 28");
552   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep+20,
553            text,FS_SMALL,FC_RED);
554   sprintf(text,"33659 Bielefeld");
555   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep+40,
556            text,FS_SMALL,FC_RED);
557   sprintf(text,"Germany");
558   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+4*ystep+60,
559            text,FS_SMALL,FC_RED);
560
561   sprintf(text,"If you have created new levels,");
562   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+7*ystep,
563            text,FS_SMALL,FC_YELLOW);
564   sprintf(text,"send them to me to include them!");
565   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+8*ystep,
566            text,FS_SMALL,FC_YELLOW);
567   sprintf(text,":-)");
568   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+ystart+9*ystep,
569            text,FS_SMALL,FC_YELLOW);
570
571   sprintf(text,"Press any key or button for main menu");
572   DrawText(SX+(SXSIZE-strlen(text)*FONT2_XSIZE)/2,SY+SYSIZE-20,
573            text,FS_SMALL,FC_BLUE);
574 }
575
576 void DrawHelpScreen()
577 {
578   int i;
579
580   CloseDoor(DOOR_CLOSE_2);
581
582   for(i=0;i<MAX_HELPSCREEN_ELS;i++)
583     helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
584   helpscreen_musicpos = 0;
585   helpscreen_state = 0;
586   DrawHelpScreenElText(0);
587   DrawHelpScreenElAction(0);
588
589   FadeToFront();
590   InitAnimation();
591   PlaySoundLoop(SND_RHYTHMLOOP);
592 }
593
594 void HandleHelpScreen(int button)
595 {
596   static long hs_delay = 0;
597   int num_helpscreen_els_pages =
598     (num_helpscreen_els + MAX_HELPSCREEN_ELS-1) / MAX_HELPSCREEN_ELS;
599   int button_released = !button;
600   int i;
601
602   if (button_released)
603   {
604     if (helpscreen_state<num_helpscreen_els_pages-1)
605     {
606       for(i=0;i<MAX_HELPSCREEN_ELS;i++)
607         helpscreen_step[i] = helpscreen_frame[i] = helpscreen_delay[i] = 0;
608       helpscreen_state++;
609       DrawHelpScreenElText(helpscreen_state*MAX_HELPSCREEN_ELS);
610       DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
611     }
612     else if (helpscreen_state<num_helpscreen_els_pages+num_bg_loops-1)
613     {
614       helpscreen_state++;
615       DrawHelpScreenMusicText(helpscreen_state-num_helpscreen_els_pages);
616     }
617     else if (helpscreen_state==num_helpscreen_els_pages+num_bg_loops-1)
618     {
619       helpscreen_state++;
620       DrawHelpScreenCreditsText();
621     }
622     else
623     {
624       FadeSounds();
625       DrawMainMenu();
626       game_status = MAINMENU;
627     }
628   }
629   else
630   {
631     if (DelayReached(&hs_delay,3))
632     {
633       if (helpscreen_state<num_helpscreen_els_pages)
634         DrawHelpScreenElAction(helpscreen_state*MAX_HELPSCREEN_ELS);
635     }
636     DoAnimation();
637   }
638
639   BackToFront();
640 }
641
642 void CheckCheat()
643 {
644   int old_handicap = player.handicap;
645
646   if (!strcmp(player.alias_name,"Artsoft"))
647     player.handicap = leveldir[leveldir_nr].levels-1;
648
649   if (player.handicap != old_handicap)
650   {
651     SavePlayerInfo(PLAYER_LEVEL);
652     level_nr = player.handicap;
653   }
654 }
655
656 void HandleTypeName(int newxpos, KeySym key)
657 {
658   static int xpos = 0, ypos = 2;
659   unsigned char ascii;
660
661   if (newxpos)
662   {
663     xpos = newxpos;
664     DrawText(SX+6*32,SY+ypos*32,player.alias_name,FS_BIG,FC_YELLOW);
665     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
666     return;
667   }
668
669   if ((key>=XK_A && key<=XK_Z) || (key>=XK_a && key<=XK_z && 
670       xpos<MAX_NAMELEN-1))
671   {
672     if (key>=XK_A && key<=XK_Z)
673       ascii = 'A'+(char)(key-XK_A);
674     if (key>=XK_a && key<=XK_z)
675       ascii = 'a'+(char)(key-XK_a);
676     player.alias_name[xpos] = ascii;
677     player.alias_name[xpos+1] = 0;
678     xpos++;
679     DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32,
680                 player.alias_name,FS_BIG,FC_YELLOW);
681     DrawTextExt(window,gc,SX+6*32,SY+ypos*32,
682                 player.alias_name,FS_BIG,FC_YELLOW);
683     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
684   }
685   else if (key==XK_Delete && xpos>0)
686   {
687     xpos--;
688     player.alias_name[xpos] = 0;
689     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
690     DrawGraphic(xpos+7,ypos,GFX_LEERRAUM);
691   }
692   else if (key==XK_Return && xpos>0)
693   {
694     DrawText(SX+6*32,SY+ypos*32,player.alias_name,FS_BIG,FC_RED);
695     DrawGraphic(xpos+6,ypos,GFX_LEERRAUM);
696     SavePlayerInfo(PLAYER_SETUP);
697     CheckCheat();
698
699     game_status = MAINMENU;
700 /*
701     DrawMainMenu();
702 */
703
704   }
705   BackToFront();
706 }
707
708 void DrawChooseLevel()
709 {
710   int i;
711
712   CloseDoor(DOOR_CLOSE_2);
713
714   ClearWindow();
715   DrawText(SX,SY,"Level Directories",FS_BIG,FC_GREEN);
716   for(i=0;i<num_leveldirs;i++)
717   {
718     DrawText(SX+32,SY+(i+2)*32,leveldir[i].name,FS_BIG,FC_YELLOW);
719     DrawGraphic(0,i+2,GFX_KUGEL_BLAU);
720   }
721
722   FadeToFront();
723   InitAnimation();
724   HandleChooseLevel(0,0,0,0,MB_MENU_MARK);
725 }
726
727 void HandleChooseLevel(int mx, int my, int dx, int dy, int button)
728 {
729   static int choice = 3;
730   static int redraw = TRUE;
731   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
732
733   if (redraw)
734   {
735     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
736     redraw = FALSE;
737   }
738
739   if (dx || dy)
740   {
741     if (dy)
742     {
743       x = 1;
744       y = choice+dy;
745     }
746     else
747       x = y = 0;
748
749     if (y<3)
750       y = 3;
751     else if (y>num_leveldirs+2)
752       y = num_leveldirs+2;
753   }
754
755   if (!mx && !my && !dx && !dy)
756   {
757     x = 1;
758     y = choice;
759   }
760
761   if (x==1 && y>=3 && y<=num_leveldirs+2)
762   {
763     if (button)
764     {
765       if (y!=choice)
766       {
767         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
768         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
769       }
770       choice = y;
771     }
772     else
773     {
774       player.leveldir_nr = leveldir_nr = y-3;
775       LoadPlayerInfo(PLAYER_LEVEL);
776       SavePlayerInfo(PLAYER_SETUP);
777       CheckCheat();
778
779       TapeErase();
780       LoadLevelTape(level_nr);
781
782       game_status = MAINMENU;
783       DrawMainMenu();
784       redraw = TRUE;
785     }
786   }
787   BackToFront();
788
789   if (game_status==CHOOSELEVEL)
790     DoAnimation();
791 }
792
793 void DrawHallOfFame(int pos)
794 {
795   int y;
796   char txt[40];
797
798   CloseDoor(DOOR_CLOSE_2);
799
800   if (pos<0) 
801     LoadScore(level_nr);
802   ClearWindow();
803   DrawText(SX+64,SY+10,"Hall Of Fame",FS_BIG,FC_YELLOW);
804   sprintf(txt,"HighScores of Level %d",level_nr);
805   DrawText(SX+256-strlen(txt)*7,SY+48,txt,FS_SMALL,FC_RED);
806   for(y=0;y<MAX_SCORE_ENTRIES;y++)
807   {
808     DrawText(SX,SY+64+y*32,".................",FS_BIG,
809              (y==pos ? FC_RED : FC_GREEN));
810     DrawText(SX,SY+64+y*32,highscore[y].Name,FS_BIG,
811              (y==pos ? FC_RED : FC_GREEN));
812     DrawText(SX+12*32,SY+64+y*32,
813              int2str(highscore[y].Score,5),FS_BIG,
814              (y==pos ? FC_RED : FC_GREEN));
815   }
816
817   FadeToFront();
818   InitAnimation();
819   PlaySound(SND_HALLOFFAME);
820 }
821
822 void HandleHallOfFame(int button)
823 {
824   int button_released = !button;
825
826   if (button_released)
827   {
828     FadeSound(SND_HALLOFFAME);
829     game_status = MAINMENU;
830     DrawMainMenu();
831     BackToFront();
832   }
833   else
834     DoAnimation();
835 }
836
837 void DrawSetupScreen()
838 {
839   int i;
840   static struct setup
841   {
842     unsigned int bit;
843     char *text, *mode[2];
844     int color[2];
845   } setup[] =
846   {
847     {SETUP_SOUND,       "Sound:",       {"on", "off"},  {FC_YELLOW,FC_BLUE}},
848     {SETUP_SOUND_LOOPS, " Sound Loops:",{"on", "off"},  {FC_YELLOW,FC_BLUE}},
849     {SETUP_SOUND_MUSIC, " Game Music:", {"on", "off"},  {FC_YELLOW,FC_BLUE}},
850     {SETUP_TOONS,       "Toons:",       {"on", "off"},  {FC_YELLOW,FC_BLUE}},
851     {SETUP_DIRECT_DRAW, "Buffered gfx:",{"off","on" },  {FC_BLUE,FC_YELLOW}},
852     {SETUP_SCROLL_DELAY,"Scroll Delay:",{"on", "off"},  {FC_YELLOW,FC_BLUE}},
853     {SETUP_FADING,      "Fading:",      {"on", "off"},  {FC_YELLOW,FC_BLUE}},
854     {SETUP_QUICK_DOORS, "Quick Doors:", {"on", "off"},  {FC_YELLOW,FC_BLUE}},
855     {SETUP_AUTO_RECORD, "Auto-Record:", {"on", "off"},  {FC_YELLOW,FC_BLUE}},
856     {SETUP_2ND_JOYSTICK,"Joystick:",    {"2nd","1st"},  {FC_YELLOW,FC_YELLOW}},
857     {0,                 "Cal. Joystick",{"",   ""},     {0,0}},
858     {0,                 "",             {"",   ""},     {0,0}},
859     {0,                 "Exit",         {"",   ""},     {0,0}},
860     {0,                 "Save and exit",{"",   ""},     {0,0}}
861   };
862
863   CloseDoor(DOOR_CLOSE_2);
864   ClearWindow();
865   DrawText(SX+16, SY+16,  "SETUP",FS_BIG,FC_YELLOW);
866
867   for(i=SETUP_SCREEN_POS_START;i<=SETUP_SCREEN_POS_END;i++)
868   {
869     int base = i - SETUP_SCREEN_POS_START;
870
871     if (i != SETUP_SCREEN_POS_EMPTY)
872     {
873       DrawGraphic(0,i,GFX_KUGEL_BLAU);
874       DrawText(SX+32,SY+i*32, setup[base].text, FS_BIG,FC_GREEN);
875     }
876
877     if (i < SETUP_SCREEN_POS_EMPTY)
878     {
879       int setting_bit = setup[base].bit;
880       int setting_pos = ((player.setup & setting_bit) != 0 ? 0 : 1);
881       DrawText(SX+14*32, SY+i*32,setup[base].mode[setting_pos],
882                FS_BIG,setup[base].color[setting_pos]);
883     }
884   }
885
886   FadeToFront();
887   InitAnimation();
888   HandleSetupScreen(0,0,0,0,MB_MENU_MARK);
889 }
890
891 void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
892 {
893   static int choice = 3;
894   static int redraw = TRUE;
895   int x = (mx+32-SX)/32, y = (my+32-SY)/32;
896   int pos_start = SETUP_SCREEN_POS_START + 1;
897   int pos_empty = SETUP_SCREEN_POS_EMPTY + 1;
898   int pos_end   = SETUP_SCREEN_POS_END   + 1;
899
900   if (redraw)
901   {
902     DrawGraphic(0,choice-1,GFX_KUGEL_ROT);
903     redraw = FALSE;
904   }
905
906   if (dx || dy)
907   {
908     if (dy)
909     {
910       x = 1;
911       y = choice+dy;
912     }
913     else
914       x = y = 0;
915
916     if (y == pos_empty)
917       y = (dy>0 ? pos_empty+1 : pos_empty-1);
918
919     if (y < pos_start)
920       y = pos_start;
921     else if (y > pos_end)
922       y = pos_end;
923   }
924
925   if (!mx && !my && !dx && !dy)
926   {
927     x = 1;
928     y = choice;
929   }
930
931   if (x==1 && y>=pos_start && y<=pos_end && y!=pos_empty)
932   {
933     if (button)
934     {
935       if (y!=choice)
936       {
937         DrawGraphic(0,y-1,GFX_KUGEL_ROT);
938         DrawGraphic(0,choice-1,GFX_KUGEL_BLAU);
939       }
940       choice = y;
941     }
942     else
943     {
944       int yy = y-1;
945
946       if (y==3 && sound_status==SOUND_AVAILABLE)
947       {
948         if (SETUP_SOUND_ON(player.setup))
949         {
950           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
951           DrawText(SX+14*32, SY+(yy+1)*32,"off",FS_BIG,FC_BLUE);
952           DrawText(SX+14*32, SY+(yy+2)*32,"off",FS_BIG,FC_BLUE);
953           player.setup &= ~SETUP_SOUND_LOOPS;
954           player.setup &= ~SETUP_SOUND_MUSIC;
955         }
956         else
957           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
958         player.setup ^= SETUP_SOUND;
959       }
960       else if (y==4 && sound_loops_allowed)
961       {
962         if (SETUP_SOUND_LOOPS_ON(player.setup))
963           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
964         else
965         {
966           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
967           DrawText(SX+14*32, SY+(yy-1)*32,"on ",FS_BIG,FC_YELLOW);
968           player.setup |= SETUP_SOUND;
969         }
970         player.setup ^= SETUP_SOUND_LOOPS;
971       }
972       else if (y==5 && sound_loops_allowed)
973       {
974         if (SETUP_SOUND_MUSIC_ON(player.setup))
975           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
976         else
977         {
978           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
979           DrawText(SX+14*32, SY+(yy-2)*32,"on ",FS_BIG,FC_YELLOW);
980           player.setup |= SETUP_SOUND;
981         }
982         player.setup ^= SETUP_SOUND_MUSIC;
983       }
984       else if (y==6)
985       {
986         if (SETUP_TOONS_ON(player.setup))
987           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
988         else
989           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
990         player.setup ^= SETUP_TOONS;
991       }
992       else if (y==7)
993       {
994         if (!SETUP_DIRECT_DRAW_ON(player.setup))
995           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
996         else
997           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
998         player.setup ^= SETUP_DIRECT_DRAW;
999       }
1000       else if (y==8)
1001       {
1002         if (SETUP_SCROLL_DELAY_ON(player.setup))
1003           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1004         else
1005           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1006         player.setup ^= SETUP_SCROLL_DELAY;
1007       }
1008       else if (y==9)
1009       {
1010         if (SETUP_FADING_ON(player.setup))
1011           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1012         else
1013           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1014         player.setup ^= SETUP_FADING;
1015       }
1016       else if (y==10)
1017       {
1018         if (SETUP_QUICK_DOORS_ON(player.setup))
1019           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1020         else
1021           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1022         player.setup ^= SETUP_QUICK_DOORS;
1023       }
1024       else if (y==11)
1025       {
1026         if (SETUP_AUTO_RECORD_ON(player.setup))
1027           DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE);
1028         else
1029           DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW);
1030         player.setup ^= SETUP_AUTO_RECORD;
1031       }
1032       else if (y==12)
1033       {
1034         if (SETUP_2ND_JOYSTICK_ON(player.setup))
1035           DrawText(SX+14*32, SY+yy*32,"1st",FS_BIG,FC_YELLOW);
1036         else
1037           DrawText(SX+14*32, SY+yy*32,"2nd",FS_BIG,FC_YELLOW);
1038         player.setup ^= SETUP_2ND_JOYSTICK;
1039       }
1040       else if (y==13)
1041       {
1042         CalibrateJoystick();
1043         redraw = TRUE;
1044       }
1045       else if (y==pos_end-1 || y==pos_end)
1046       {
1047         if (y==pos_end)
1048         {
1049           SavePlayerInfo(PLAYER_SETUP);
1050           SaveJoystickData();
1051         }
1052
1053         game_status = MAINMENU;
1054         DrawMainMenu();
1055         redraw = TRUE;
1056       }
1057     }
1058   }
1059   BackToFront();
1060
1061   if (game_status==SETUP)
1062     DoAnimation();
1063 }
1064
1065 void CalibrateJoystick()
1066 {
1067 #ifdef __FreeBSD__
1068   struct joystick joy_ctrl;
1069 #else
1070   struct joystick_control
1071   {
1072     int buttons;
1073     int x;
1074     int y;
1075   } joy_ctrl;
1076 #endif
1077
1078   int new_joystick_xleft, new_joystick_xright, new_joystick_xmiddle;
1079   int new_joystick_yupper, new_joystick_ylower, new_joystick_ymiddle;
1080
1081   if (joystick_status==JOYSTICK_OFF)
1082     goto error_out;
1083
1084   ClearWindow();
1085   DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW);
1086   DrawText(SX+16, SY+8*32, " THE UPPER LEFT ",FS_BIG,FC_YELLOW);
1087   DrawText(SX+16, SY+9*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW);
1088   BackToFront();
1089
1090 #ifdef __FreeBSD__
1091   joy_ctrl.b1 = joy_ctrl.b2 = 0;
1092 #else
1093   joy_ctrl.buttons = 0;
1094 #endif
1095   while(Joystick() & JOY_BUTTON);
1096 #ifdef __FreeBSD__
1097   while(!(joy_ctrl.b1||joy_ctrl.b2))
1098 #else
1099   while(!joy_ctrl.buttons)
1100 #endif
1101   {
1102     if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1103     {
1104       joystick_status=JOYSTICK_OFF;
1105       goto error_out;
1106     }
1107     Delay(10000);
1108   }
1109
1110   new_joystick_xleft = joy_ctrl.x;
1111   new_joystick_yupper = joy_ctrl.y;
1112
1113   ClearWindow();
1114   DrawText(SX+16, SY+7*32, "MOVE JOYSTICK TO",FS_BIG,FC_YELLOW);
1115   DrawText(SX+32, SY+8*32, "THE LOWER RIGHT",FS_BIG,FC_YELLOW);
1116   DrawText(SX+16, SY+9*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW);
1117   BackToFront();
1118
1119 #ifdef __FreeBSD__
1120   joy_ctrl.b1 = joy_ctrl.b2 = 0;
1121 #else
1122   joy_ctrl.buttons = 0;
1123 #endif
1124   while(Joystick() & JOY_BUTTON);
1125 #ifdef __FreeBSD__
1126   while(!(joy_ctrl.b1||joy_ctrl.b2))
1127 #else
1128   while(!joy_ctrl.buttons)
1129 #endif
1130   {
1131     if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1132     {
1133       joystick_status=JOYSTICK_OFF;
1134       goto error_out;
1135     }
1136     Delay(10000);
1137   }
1138
1139   new_joystick_xright = joy_ctrl.x;
1140   new_joystick_ylower = joy_ctrl.y;
1141
1142   ClearWindow();
1143   DrawText(SX+32, SY+16+7*32, "CENTER JOYSTICK",FS_BIG,FC_YELLOW);
1144   DrawText(SX+16, SY+16+8*32, "AND PRESS BUTTON",FS_BIG,FC_YELLOW);
1145   BackToFront();
1146
1147 #ifdef __FreeBSD__
1148   joy_ctrl.b1 = joy_ctrl.b2 = 0;
1149 #else
1150   joy_ctrl.buttons = 0;
1151 #endif
1152   while(Joystick() & JOY_BUTTON);
1153 #ifdef __FreeBSD__
1154   while(!(joy_ctrl.b1||joy_ctrl.b2))
1155 #else
1156   while(!joy_ctrl.buttons)
1157 #endif
1158   {
1159     if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
1160     {
1161       joystick_status=JOYSTICK_OFF;
1162       goto error_out;
1163     }
1164     Delay(10000);
1165   }
1166
1167   new_joystick_xmiddle = joy_ctrl.x;
1168   new_joystick_ymiddle = joy_ctrl.y;
1169
1170   joystick[joystick_nr].xleft = new_joystick_xleft;
1171   joystick[joystick_nr].yupper = new_joystick_yupper;
1172   joystick[joystick_nr].xright = new_joystick_xright;
1173   joystick[joystick_nr].ylower = new_joystick_ylower;
1174   joystick[joystick_nr].xmiddle = new_joystick_xmiddle;
1175   joystick[joystick_nr].ymiddle = new_joystick_ymiddle;
1176
1177   CheckJoystickData();
1178
1179   DrawSetupScreen();
1180   while(Joystick() & JOY_BUTTON);
1181   return;
1182
1183   error_out:
1184
1185   ClearWindow();
1186   DrawText(SX+16, SY+16, "NO JOYSTICK",FS_BIG,FC_YELLOW);
1187   DrawText(SX+16, SY+48, " AVAILABLE ",FS_BIG,FC_YELLOW);
1188   Delay(3000000);
1189   DrawSetupScreen();
1190 }
1191
1192 void HandleGameActions()
1193 {
1194   if (game_status != PLAYING)
1195     return;
1196
1197   if (LevelSolved)
1198     GameWon();
1199
1200   if (GameOver && !TAPE_IS_STOPPED(tape))
1201     TapeStop();
1202
1203   GameActions();
1204 }
1205
1206 void HandleVideoButtons(int mx, int my, int button)
1207 {
1208   if (game_status != MAINMENU && game_status != PLAYING)
1209     return;
1210
1211   switch(CheckVideoButtons(mx,my,button))
1212   {
1213     case BUTTON_VIDEO_EJECT:
1214       TapeStop();
1215       if (TAPE_IS_EMPTY(tape))
1216       {
1217         LoadLevelTape(level_nr);
1218         if (TAPE_IS_EMPTY(tape))
1219           AreYouSure("No tape for this level !",AYS_CONFIRM);
1220       }
1221       else
1222       {
1223         if (tape.changed)
1224           SaveLevelTape(tape.level_nr);
1225         TapeErase();
1226       }
1227       DrawCompleteVideoDisplay();
1228       break;
1229     case BUTTON_VIDEO_STOP:
1230       TapeStop();
1231       break;
1232     case BUTTON_VIDEO_PAUSE:
1233       TapeTogglePause();
1234       break;
1235     case BUTTON_VIDEO_REC:
1236       if (TAPE_IS_STOPPED(tape))
1237       {
1238         TapeStartRecording();
1239         game_status = PLAYING;
1240         InitGame();
1241       }
1242       else if (tape.pausing)
1243       {
1244         if (tape.playing)       /* PLAYING -> PAUSING -> RECORDING */
1245         {
1246           tape.pos[tape.counter].delay = tape.delay_played;
1247           tape.playing = FALSE;
1248           tape.recording = TRUE;
1249
1250           DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON,0);
1251         }
1252         else
1253           TapeTogglePause();
1254       }
1255       break;
1256     case BUTTON_VIDEO_PLAY:
1257       if (TAPE_IS_EMPTY(tape))
1258         break;
1259
1260       if (TAPE_IS_STOPPED(tape))
1261       {
1262         TapeStartPlaying();
1263         game_status = PLAYING;
1264         InitGame();
1265       }
1266       else if (tape.playing)
1267       {
1268         if (tape.pausing)                       /* PAUSE -> PLAY */
1269           TapeTogglePause();
1270         else if (!tape.fast_forward)            /* PLAY -> FAST FORWARD PLAY */
1271         {
1272           tape.fast_forward = TRUE;
1273           DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1274         }
1275         else if (!tape.pause_before_death)      /* FFWD PLAY -> + AUTO PAUSE */
1276         {
1277           tape.pause_before_death = TRUE;
1278           DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, VIDEO_DISPLAY_LABEL_ONLY);
1279         }
1280         else                                    /* -> NORMAL PLAY */
1281         {
1282           tape.fast_forward = FALSE;
1283           tape.pause_before_death = FALSE;
1284           DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PAUSE_OFF, 0);
1285         }
1286       }
1287       break;
1288     default:
1289       break;
1290   }
1291
1292   BackToFront();
1293 }
1294
1295 void HandleSoundButtons(int mx, int my, int button)
1296 {
1297   if (game_status != PLAYING)
1298     return;
1299
1300   switch(CheckSoundButtons(mx,my,button))
1301   {
1302     case BUTTON_SOUND_MUSIC:
1303       if (sound_music_on)
1304       { 
1305         sound_music_on = FALSE;
1306         player.setup &= ~SETUP_SOUND_MUSIC;
1307         FadeSound(background_loop[level_nr % num_bg_loops]);
1308         DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF);
1309       }
1310       else if (sound_loops_allowed)
1311       { 
1312         sound_on = sound_music_on = TRUE;
1313         player.setup |= (SETUP_SOUND | SETUP_SOUND_MUSIC);
1314         PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
1315         DrawSoundDisplay(BUTTON_SOUND_MUSIC_ON);
1316       }
1317       else
1318         DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF);
1319       break;
1320     case BUTTON_SOUND_LOOPS:
1321       if (sound_loops_on)
1322       { 
1323         sound_loops_on = FALSE;
1324         player.setup &= ~SETUP_SOUND_LOOPS;
1325         DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF);
1326       }
1327       else if (sound_loops_allowed)
1328       { 
1329         sound_on = sound_loops_on = TRUE;
1330         player.setup |= (SETUP_SOUND | SETUP_SOUND_LOOPS);
1331         DrawSoundDisplay(BUTTON_SOUND_LOOPS_ON);
1332       }
1333       else
1334         DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF);
1335       break;
1336     case BUTTON_SOUND_SIMPLE:
1337       if (sound_simple_on)
1338       { 
1339         sound_simple_on = FALSE;
1340         player.setup &= ~SETUP_SOUND;
1341         DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF);
1342       }
1343       else if (sound_status==SOUND_AVAILABLE)
1344       { 
1345         sound_on = sound_simple_on = TRUE;
1346         player.setup |= SETUP_SOUND;
1347         DrawSoundDisplay(BUTTON_SOUND_SIMPLE_ON);
1348       }
1349       else
1350         DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF);
1351       break;
1352     default:
1353       break;
1354   }
1355
1356   BackToFront();
1357 }
1358
1359 void HandleGameButtons(int mx, int my, int button)
1360 {
1361   if (game_status != PLAYING)
1362     return;
1363
1364   switch(CheckGameButtons(mx,my,button))
1365   {
1366     case BUTTON_GAME_STOP:
1367       if (GameOver)
1368       {
1369         CloseDoor(DOOR_CLOSE_1);
1370         game_status = MAINMENU;
1371         DrawMainMenu();
1372         break;
1373       }
1374
1375       if (AreYouSure("Do you really want to quit the game ?",
1376                       AYS_ASK | AYS_STAY_CLOSED))
1377       { 
1378         game_status = MAINMENU;
1379         DrawMainMenu();
1380       }
1381       else
1382         OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
1383       break;
1384     case BUTTON_GAME_PAUSE:
1385       if (tape.pausing)
1386       {
1387         tape.pausing = FALSE;
1388         DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
1389       }
1390       else
1391       {
1392         tape.pausing = TRUE;
1393         DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0);
1394       }
1395       break;
1396     case BUTTON_GAME_PLAY:
1397       if (tape.pausing)
1398       {
1399         tape.pausing = FALSE;
1400         DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
1401       }
1402       break;
1403     default:
1404       break;
1405   }
1406
1407   BackToFront();
1408 }