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