Fixed more parse errors.
[supertux.git] / src / leveleditor.c
1
2 /***************************************************************************
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  ***************************************************************************/
10   
11 /*  December 28, 2003 - December 29, 2003 */
12  
13 /* leveleditor.c - A built-in level editor for SuperTux
14  by Ricardo Cruz <rick2@aeiou.pt>                      */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <errno.h>
20 #include <unistd.h>
21 #include <SDL.h>
22 #include <SDL_image.h>
23
24 #include "leveleditor.h"
25 #include "gameloop.h"
26 #include "screen.h"
27 #include "defines.h"
28 #include "globals.h"
29 #include "setup.h"
30 #include "menu.h"
31
32 #include "badguy.h"
33
34 char levelname[60];
35 char leveltheme[60];
36 bad_guy_type bad_guys[NUM_BAD_GUYS];
37 SDL_Surface *img_bsod_left[4], *img_laptop_left[3], *img_money_left[2];
38 char song_title[60];
39 char levelfilename[100];
40
41 int time_left;
42 unsigned char* tiles[15];
43 int bkgd_red, bkgd_green, bkgd_blue, level_width;
44
45 SDL_Surface *selection;
46
47 /* definitions to aid development */
48 #define DONE_LEVELEDITOR    1
49 #define DONE_QUIT        2
50 #define DONE_CHANGELEVEL  3
51
52 /* definitions that affect gameplay */
53 #define KEY_CURSOR_SPEED 32
54 #define KEY_CURSOR_FASTSPEED 64
55 #define KEY_LEFT_MARGIN 160
56 #define KEY_RIGHT_MARGIN 480
57
58 #define MOUSE_LEFT_MARGIN 32
59 #define MOUSE_RIGHT_MARGIN 608
60 #define MOUSE_POS_SPEED 32
61
62 /* gameloop funcs declerations */
63
64 void loadlevelgfx(void);
65 void unloadlevelgfx(void);
66 void add_bad_guy(int x, int y, int kind);
67 void loadshared(void);
68 void unloadshared(void);
69 void drawshape(int x, int y, unsigned char c);
70
71 /* own declerations */
72
73 void savelevel();
74 void le_loadlevel(void);
75 void le_change(int x, int y, int sx, unsigned char c);
76 void showhelp();
77
78 /* FIXME: Needs to be implemented. It should ask the user for the level(file)name and then let him create a new level based on this. */
79 void newlevel()
80 {
81 }
82
83 /* FIXME: It should let select the user a level, which is in the leveldirectory and then load it. */
84 void selectlevel()
85 {
86 }
87
88 int leveleditor()
89 {
90   char str[10];
91   int done;
92   int x, y, i;  /* for cicles */
93   int pos_x, cursor_x, cursor_y, old_cursor_x, fire;
94   SDL_Event event;
95   SDLKey key;
96   SDLMod keymod;
97
98
99   strcpy(levelfilename,"level1");
100
101   initmenu();
102   menumenu = MENU_LEVELEDITOR;
103   show_menu = YES;
104
105   loadshared();
106   le_loadlevel();
107   loadlevelgfx();
108
109   selection = load_image(DATA_PREFIX "/images/leveleditor/select.png", USE_ALPHA);
110
111   done = 0;
112   pos_x = 0;
113   cursor_x = 3*32;
114   old_cursor_x = cursor_x;
115   cursor_y = 2*32;
116   fire = DOWN;
117
118   SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
119
120   while(1)
121     {
122       SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, bkgd_red, bkgd_green, bkgd_blue));
123
124       keymod = SDL_GetModState();
125
126       while(SDL_PollEvent(&event))
127         {
128           // testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events
129           switch(event.type)
130             {
131             case SDL_KEYDOWN:   // key pressed
132               key = event.key.keysym.sym;
133               if(show_menu)
134                 {
135                   menu_event(key);
136                   break;
137                 }
138               switch(key)
139                 {
140                 case SDLK_LEFT:
141                   if(fire == DOWN)
142                     cursor_x -= KEY_CURSOR_SPEED;
143                   else
144                     cursor_x -= KEY_CURSOR_FASTSPEED;
145
146                   if(cursor_x < 0)
147                     cursor_x = 0;
148                   break;
149                 case SDLK_RIGHT:
150                   if(fire == DOWN)
151                     cursor_x += KEY_CURSOR_SPEED;
152                   else
153                     cursor_x += KEY_CURSOR_FASTSPEED;
154
155                   if(cursor_x > (level_width*32) - 1)
156                     cursor_x = (level_width*32) - 1;
157                   break;
158                 case SDLK_UP:
159                   if(fire == DOWN)
160                     cursor_y -= KEY_CURSOR_SPEED;
161                   else
162                     cursor_y -= KEY_CURSOR_FASTSPEED;
163
164                   if(cursor_y < 0)
165                     cursor_y = 0;
166                   break;
167                 case SDLK_DOWN:
168                   if(fire == DOWN)
169                     cursor_y += KEY_CURSOR_SPEED;
170                   else
171                     cursor_y += KEY_CURSOR_FASTSPEED;
172
173                   if(cursor_y > 480-32)
174                     cursor_y = 480-32;
175                   break;
176                 case SDLK_LCTRL:
177                   fire = UP;
178                   break;
179                 case SDLK_F1:
180                   showhelp();
181                   break;
182                 case SDLK_HOME:
183                   cursor_x = 0;
184                   break;
185                 case SDLK_END:
186                   cursor_x = (level_width * 32) - 32;
187                   break;
188                 case SDLK_PERIOD:
189                   le_change(cursor_x, cursor_y, 0, '.');
190                   break;
191                 case SDLK_a:
192                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
193                     le_change(cursor_x, cursor_y, 0, 'A');
194                   else
195                     le_change(cursor_x, cursor_y, 0, 'a');
196                   break;
197                 case SDLK_b:
198                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
199                     le_change(cursor_x, cursor_y, 0, 'B');
200                   break;
201                 case SDLK_c:
202                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
203                     le_change(cursor_x, cursor_y, 0, 'C');
204                   else
205                     le_change(cursor_x, cursor_y, 0, 'c');
206                   break;
207                 case SDLK_d:
208                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
209                     le_change(cursor_x, cursor_y, 0, 'D');
210                   else
211                     le_change(cursor_x, cursor_y, 0, 'd');
212                   break;
213                 case SDLK_e:
214                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
215                     le_change(cursor_x, cursor_y, 0, 'E');
216                   else
217                     le_change(cursor_x, cursor_y, 0, 'e');
218                   break;
219                 case SDLK_f:
220                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
221                     le_change(cursor_x, cursor_y, 0, 'F');
222                   else
223                     le_change(cursor_x, cursor_y, 0, 'f');
224                   break;
225                 case SDLK_g:
226                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
227                     le_change(cursor_x, cursor_y, 0, 'G');
228                   else
229                     le_change(cursor_x, cursor_y, 0, 'g');
230                   break;
231                 case SDLK_h:
232                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
233                     le_change(cursor_x, cursor_y, 0, 'H');
234                   else
235                     le_change(cursor_x, cursor_y, 0, 'h');
236                   break;
237                 case SDLK_i:
238                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
239                     le_change(cursor_x, cursor_y, 0, 'I');
240                   else
241                     le_change(cursor_x, cursor_y, 0, 'i');
242                   break;
243                 case SDLK_j:
244                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
245                     le_change(cursor_x, cursor_y, 0, 'J');
246                   else
247                     le_change(cursor_x, cursor_y, 0, 'j');
248                   break;
249                 case SDLK_x:
250                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
251                     le_change(cursor_x, cursor_y, 0, 'X');
252                   else
253                     le_change(cursor_x, cursor_y, 0, 'x');
254                   break;
255                 case SDLK_y:
256                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
257                     le_change(cursor_x, cursor_y, 0, 'Y');
258                   else
259                     le_change(cursor_x, cursor_y, 0, 'y');
260                   break;
261                 case SDLK_LEFTBRACKET:
262                   le_change(cursor_x, cursor_y, 0, '[');
263                   break;
264                 case SDLK_RIGHTBRACKET:
265                   le_change(cursor_x, cursor_y, 0, ']');
266                   break;
267                 case SDLK_HASH:
268                 case SDLK_3:
269                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
270                     le_change(cursor_x, cursor_y, 0, '#');
271                   break;
272                 case SDLK_DOLLAR:
273                 case SDLK_4:
274                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
275                     le_change(cursor_x, cursor_y, 0, '$');
276                   break;
277                 case SDLK_BACKSLASH:
278                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
279                     le_change(cursor_x, cursor_y, 0, '|');
280                   else
281                     le_change(cursor_x, cursor_y, 0, '\\');
282                   break;
283                 case SDLK_CARET:
284                   le_change(cursor_x, cursor_y, 0, '^');
285                   break;
286                 case SDLK_AMPERSAND:
287                 case SDLK_6:
288                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
289                     le_change(cursor_x, cursor_y, 0, '&');
290                   break;
291                 case SDLK_EQUALS:
292                 case SDLK_0:
293                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
294                     le_change(cursor_x, cursor_y, 0, '=');
295                   else          /* let's add a bad guy */
296                     le_change(cursor_x, cursor_y, 0, '0');
297
298                   for(i = 0; i < NUM_BAD_GUYS; ++i)
299                     if (bad_guys[i].alive == NO)
300                       {
301                         bad_guys[i].alive = YES;
302                         bad_guys[i].kind = BAD_BSOD;
303                         bad_guys[i].x = (((int)cursor_x/32)*32);
304                         bad_guys[i].y = (((int)cursor_y/32)*32);
305                         i = NUM_BAD_GUYS;
306                       }
307                   break;
308                 case SDLK_1:
309                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
310                     le_change(cursor_x, cursor_y, 0, '!');
311                   else          /* let's add a bad guy */
312                     le_change(cursor_x, cursor_y, 0, '1');
313
314                   for(i = 0; i < NUM_BAD_GUYS; ++i)
315                     if (bad_guys[i].alive == NO)
316                       {
317                         bad_guys[i].alive = YES;
318                         bad_guys[i].kind = BAD_LAPTOP;
319                         bad_guys[i].x = (((int)cursor_x/32)*32);
320                         bad_guys[i].y = (((int)cursor_y/32)*32);
321                         i = NUM_BAD_GUYS;
322                       }
323                   break;
324                 case SDLK_2:
325                   le_change(cursor_x, cursor_y, 0, '2');
326
327                   for(i = 0; i < NUM_BAD_GUYS; ++i)
328                     if (bad_guys[i].alive == NO)
329                       {
330                         bad_guys[i].alive = YES;
331                         bad_guys[i].kind = BAD_MONEY;
332                         bad_guys[i].x = (((int)cursor_x/32)*32);
333                         bad_guys[i].y = (((int)cursor_y/32)*32);
334                         i = NUM_BAD_GUYS;
335                       }
336                   break;
337                 case SDLK_PLUS:
338                   if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
339                     le_change(cursor_x, cursor_y, 0, '*');
340                   break;
341                 default:
342                   break;
343                 }
344               break;
345             case SDL_KEYUP:     // key released
346               switch(event.key.keysym.sym)
347                 {
348                 case SDLK_LCTRL:
349                   fire = DOWN;
350                   break;
351                 case SDLK_ESCAPE:
352                   if(!show_menu)
353                     show_menu = YES;
354                   else
355                     show_menu = NO;
356                   break;
357                 default:
358                   break;
359                 }
360               break;
361             case SDL_MOUSEBUTTONDOWN:
362               if(event.button.button == SDL_BUTTON_LEFT)
363                 {
364                   x = event.motion.x;
365                   y = event.motion.y;
366
367                   cursor_x = ((int)(pos_x + x) / 32) * 32;
368                   cursor_y = ((int) y / 32) * 32;
369                 }
370               break;
371             case SDL_MOUSEMOTION:
372               x = event.motion.x;
373               y = event.motion.y;
374
375               cursor_x = ((int)(pos_x + x) / 32) * 32;
376               cursor_y = ((int) y / 32) * 32;
377               break;
378             case SDL_QUIT:      // window closed
379               done = DONE_QUIT;
380               break;
381             default:
382               break;
383             }
384         }
385
386       /* mouse movements */
387       x = event.motion.x;
388       if(x < MOUSE_LEFT_MARGIN)
389         pos_x -= MOUSE_POS_SPEED;
390       else if(x > MOUSE_RIGHT_MARGIN)
391         pos_x += MOUSE_POS_SPEED;
392
393       if(old_cursor_x != cursor_x)
394         {
395           if(cursor_x < pos_x + KEY_LEFT_MARGIN)
396             pos_x = cursor_x - KEY_LEFT_MARGIN;
397
398           if(cursor_x > pos_x + KEY_RIGHT_MARGIN)
399             pos_x = cursor_x - KEY_RIGHT_MARGIN;
400         }
401
402       if(pos_x < 0)
403         pos_x = 0;
404       if(pos_x > (level_width * 32) - 640)
405         pos_x = (level_width * 32) - 640;
406
407       old_cursor_x = cursor_x;
408
409       for (y = 0; y < 15; ++y)
410         for (x = 0; x < 21; ++x)
411           drawshape(x * 32, y * 32, tiles[y][x + (pos_x / 32)]);
412
413       /* Draw the Bad guys: */
414       for (i = 0; i < NUM_BAD_GUYS; ++i)
415         {
416           /* printf("\nbad_guys[%i].alive = %i", i, bad_guys[i].alive); */
417           if(bad_guys[i].alive == NO)
418             continue;
419           /* to support frames: img_bsod_left[(frame / 5) % 4] */
420           if(bad_guys[i].kind == BAD_BSOD)
421             drawimage(img_bsod_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE);
422           else if(bad_guys[i].kind == BAD_LAPTOP)
423             drawimage(img_laptop_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE);
424           else if (bad_guys[i].kind == BAD_MONEY)
425             drawimage(img_money_left[0], ((int)(bad_guys[i].x - pos_x)/32)*32, bad_guys[i].y, NO_UPDATE);
426         }
427
428
429       drawimage(selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE);
430
431       sprintf(str, "%d", time_left);
432       drawtext("TIME", 324, 0, letters_blue, NO_UPDATE, 1);
433       drawtext(str, 404, 0, letters_gold, NO_UPDATE, 1);
434
435       sprintf(str, "%s", levelname);
436       drawtext("NAME", 0, 0, letters_blue, NO_UPDATE, 1);
437       drawtext(str, 80, 0, letters_gold, NO_UPDATE, 1);
438
439       drawtext("F1 for Help", 10, 430, letters_blue, NO_UPDATE, 1);
440
441       if(show_menu)
442         {
443           done = drawmenu();
444           if(done)
445             return 0;
446         }
447       if(done == DONE_QUIT)
448         return 1;
449
450       SDL_Delay(50);
451       SDL_Flip(screen);
452     }
453
454   unloadlevelgfx();
455   unloadshared();
456
457   SDL_FreeSurface(selection);
458
459   /*if(done == DONE_SAVE)*/     /* let's save the changes       */
460   /*    savelevel();*/
461   /*
462   if(done == DONE_CHANGELEVEL)           change level 
463         return leveleditor(level);
464   */
465   return done;
466 }
467
468 void le_change(int x, int y, int sx, unsigned char c)
469 {
470   int xx, yy;
471   int i;
472
473   yy = (y / 32);
474   xx = ((x + sx) / 32);
475
476   /* if there is a bad guy over there, remove it */
477   for(i = 0; i < NUM_BAD_GUYS; ++i)
478     if (bad_guys[i].alive)
479       if(xx == bad_guys[i].x/32 && yy == bad_guys[i].y/32)
480         bad_guys[i].alive = NO;
481
482
483   if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
484     tiles[yy][xx] = c;
485 }
486
487 /* Save data for this level: */
488 void savelevel(void)
489 {
490   FILE * fi;
491   char * filename;
492   int y;
493   char str[80];
494
495   /* Save data file: */
496
497   filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
498   sprintf(filename, "%s/levels/%s.dat", DATA_PREFIX, levelfilename);
499   fi = fopen(filename, "w");
500   if (fi == NULL)
501     {
502       perror(filename);
503       st_shutdown();
504       free(filename);
505       exit(-1);
506     }
507   free(filename);
508
509
510   /* sptrinf("# Level created by SuperTux built-in editor", fi); */
511
512   fputs(levelname, fi);
513   fputs("\n", fi);
514   fputs(leveltheme, fi);
515   fputs("\n", fi);
516   sprintf(str, "%d\n", time_left);      /* time */
517   fputs(str, fi);
518   fputs(song_title, fi);        /* song filename */
519   sprintf(str, "%d\n", bkgd_red);       /* red background color */
520   fputs(str, fi);
521   sprintf(str, "%d\n", bkgd_green);     /* green background color */
522   fputs(str, fi);
523   sprintf(str, "%d\n", bkgd_blue);      /* blue background color */
524   fputs(str, fi);
525   sprintf(str, "%d\n", level_width);    /* level width */
526   fputs(str, fi);
527
528   for(y = 0; y < 15; ++y)
529     {
530       fputs(tiles[y], fi);
531       fputs("\n", fi);
532     }
533
534   fclose(fi);
535
536   drawcenteredtext("SAVED!", 240, letters_gold, NO_UPDATE, 1);
537   SDL_Flip(screen);
538   SDL_Delay(1000);
539 }
540
541
542 /* I had to copy loadlevel, because loadlevel changes the tiles.
543  For intance, badguys are removed from the tiles and we have to
544  keep them there.                                             */
545
546 /* Load data for this level: */
547
548 void le_loadlevel(void)
549 {
550   FILE * fi;
551   char * filename;
552   int x, y;
553   char str[80];
554   char* line = malloc(sizeof(char)*10);/*[LEVEL_WIDTH + 5];*/
555
556   /* Load data file: */
557
558   filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
559   sprintf(filename, "%s/levels/%s.dat", DATA_PREFIX, levelfilename);
560   fi = fopen(filename, "r");
561   if (fi == NULL)
562     {
563       perror(filename);
564       st_shutdown();
565       free(filename);
566       exit(-1);
567     }
568   free(filename);
569
570   /* (Level title) */
571   fgets(str, 20, fi);
572   strcpy(levelname, str);
573   levelname[strlen(levelname)-1] = '\0';
574
575   /* (Level theme) */
576   fgets(str, 20, fi);
577   strcpy(leveltheme, str);
578   leveltheme[strlen(leveltheme)-1] = '\0';
579
580   fgets(line, 10, fi);
581   time_left = atoi(line);
582   fgets(str, 60, fi);
583   song_title[0]='\0';
584   strcpy(song_title,str);
585   fgets(line, 10, fi);
586   bkgd_red = atoi(line);
587   fgets(line, 10, fi);
588   bkgd_green= atoi(line);
589   fgets(line, 10, fi);
590   bkgd_blue = atoi(line);
591   fgets(line, 10, fi);
592   level_width = atoi(line);
593
594   free(line);
595   line = malloc(level_width*sizeof(char)+5);
596
597   for (y = 0; y < 15; ++y)
598     {
599       fgets(line, level_width + 5, fi);
600       line[strlen(line) - 1] = '\0';
601       free(tiles[y]);
602       tiles[y] = malloc((strlen(line)+5)*sizeof(char));
603       strcpy(tiles[y], line);
604     }
605
606   fclose(fi);
607
608   /* Activate bad guys: */
609
610   /* as oposed to the gameloop.c func, this one doesn't remove
611   the badguys from tiles                                    */
612
613   for (y = 0; y < 15; ++y)
614     for (x = 0; x < level_width; ++x)
615       if (tiles[y][x] >= '0' && tiles[y][x] <= '9')
616         add_bad_guy(x * 32, y * 32, tiles[y][x] - '0');
617
618
619   /* Set defaults: */
620
621   if(time_left == 0)
622     time_left = 255;
623
624
625   /* Level Intro: */
626
627   clearscreen(0, 0, 0);
628
629   sprintf(str, "Editing Level %s", levelfilename);
630   drawcenteredtext(str, 200, letters_red, NO_UPDATE, 1);
631
632   sprintf(str, "%s", levelname);
633   drawcenteredtext(str, 224, letters_gold, NO_UPDATE, 1);
634
635   SDL_Flip(screen);
636
637   SDL_Delay(1000);
638 }
639
640 void showhelp()
641 {
642   SDL_Event event;
643   int done;
644   char *text[] = {
645                    "X/x - Brick0",
646                    "Y/y - Brick1",
647                    "A/B/! - Box full",
648                    "a - Box empty",
649                    "C-F - Cloud0",
650                    "c-f - Cloud1",
651                    "G-J - Bkgd0",
652                    "g-j - Bkgd1",
653                    "# - Solid0",
654                    "[ - Solid1",
655                    "= - Solid2",
656                    "] - Solid3",
657                    "$ - Distro",
658                    "^ - Waves",
659                    "* - Poletop",
660                    "| - Pole",
661                    "\\ - Flag",
662                    "& - Water",
663                    "0-2 - BadGuys",
664                    "./Del - Remove tile",
665                    "Esc - Menu"};
666   int i;
667
668
669   drawcenteredtext("- Help -", 30, letters_red, NO_UPDATE, 1);
670   drawtext("Keys:", 80, 60, letters_gold, NO_UPDATE, 1);
671
672   for(i = 0; i < sizeof(text)/sizeof(char *); i++)
673     drawtext(text[i], 40, 90+(i*16), letters_blue, NO_UPDATE, 1);
674
675   SDL_Flip(screen);
676
677   done = 0;
678
679   while(done == 0)
680     while(SDL_PollEvent(&event))
681       switch(event.type)
682         {
683         case SDL_KEYDOWN:               // key pressed
684           done = 1;
685           break;
686         default:
687           break;
688         }
689 }