disables key repeating at the end
[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   SDL_EnableKeyRepeat(0, 0);    // disables key repeating
240
241   button_free(&le_test_level_bt);
242   level_free_gfx();
243   level_free(&le_current_level);
244   unloadshared();
245   arrays_free();
246   texture_free(&le_selection);
247 }
248
249 void le_drawlevel()
250 {
251   int y,x,i,s;
252   static char str[LEVEL_NAME_MAX];
253
254   /* Draw the real background */
255   if(le_current_level.bkgd_image[0] != '\0')
256     {
257       s = pos_x / 30;
258       texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s - 32, img_bkgd.h, NO_UPDATE);
259       texture_draw_part(&img_bkgd,0,0,screen->w - s - 32 ,0,s,img_bkgd.h, NO_UPDATE);
260     }
261   else
262     {
263       clearscreen(le_current_level.bkgd_red, le_current_level.bkgd_green, le_current_level.bkgd_blue);
264     }
265
266   /*       clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); */
267
268   for (y = 0; y < 15; ++y)
269     for (x = 0; x < 19; ++x)
270       {
271         drawshape(x * 32, y * 32, le_current_level.tiles[y][x + (pos_x / 32)]);
272       }
273
274   /* draw whats inside stuff when cursor is selecting those */
275   cursor_tile = le_current_level.tiles[cursor_y/32][cursor_x/32];
276   switch(cursor_tile)
277     {
278     case 'B':
279       texture_draw(&img_mints, cursor_x - pos_x, cursor_y, NO_UPDATE);
280       break;
281     case '!':
282       texture_draw(&img_golden_herring, cursor_x - pos_x, cursor_y, NO_UPDATE);
283       break;
284     case 'x':
285     case 'y':
286     case 'A':
287       texture_draw(&img_distro[(le_frame / 5) % 4], cursor_x - pos_x, cursor_y, NO_UPDATE);
288       break;
289     default:
290       break;
291     }
292
293   /* Draw the Bad guys: */
294   for (i = 0; i < num_bad_guys; ++i)
295     {
296       if(bad_guys[i].base.alive == NO)
297         continue;
298       /* to support frames: img_bsod_left[(frame / 5) % 4] */
299       if(bad_guys[i].kind == BAD_BSOD)
300         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);
301       else if(bad_guys[i].kind == BAD_LAPTOP)
302         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);
303       else if (bad_guys[i].kind == BAD_MONEY)
304         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);
305     }
306
307   /* draw a grid (if selected) */
308   if(le_show_grid)
309     {
310       for(x = 0; x < 19; x++)
311         fillrect(x*32, 0, 1, screen->h, 225, 225, 225,255);
312       for(y = 0; y < 15; y++)
313         fillrect(0, y*32, screen->w - 32, 1, 225, 225, 225,255);
314     }
315
316   fillrect(screen->w - 32, 0, 32, screen->h, 50, 50, 50,255);
317   drawshape(19 * 32, 14 * 32, le_current_tile);
318
319   button_draw(&le_test_level_bt);
320   button_draw(&le_next_level_bt);
321   button_draw(&le_previous_level_bt);
322   button_draw(&le_rubber_bt);
323   
324   texture_draw(&le_selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE);
325
326   sprintf(str, "%d", le_current_level.time_left);
327   text_draw(&white_text, "TIME", 324, 0, 1, NO_UPDATE);
328   text_draw(&gold_text, str, 404, 0, 1, NO_UPDATE);
329
330   text_draw(&white_text, "NAME", 0, 0, 1, NO_UPDATE);
331   text_draw(&gold_text, le_current_level.name, 80, 0, 1, NO_UPDATE);
332
333   sprintf(str, "%d/%d", le_level,le_level_subset.levels);
334   text_draw(&white_text, "NUMB", 0, 20, 1, NO_UPDATE);
335   text_draw(&gold_text, str, 80, 20, 1, NO_UPDATE);
336
337   text_draw(&white_small_text, "F1 for Help", 10, 430, 1, NO_UPDATE);
338   text_draw(&white_small_text, "F2 for Testing", 150, 430, 1, NO_UPDATE);
339 }
340
341 void le_checkevents()
342 {
343   SDL_Event event;
344   SDLKey key;
345   SDLMod keymod;
346   int x,y;
347
348   keymod = SDL_GetModState();
349
350   while(SDL_PollEvent(&event))
351     {
352       /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
353       switch(event.type)
354         {
355         case SDL_KEYDOWN:       // key pressed
356           key = event.key.keysym.sym;
357           if(show_menu)
358             {
359               menu_event(&event.key.keysym);
360               break;
361             }
362           switch(key)
363             {
364             case SDLK_ESCAPE:
365               if(!show_menu)
366                 show_menu = YES;
367               else
368                 show_menu = NO;
369               break;
370             case SDLK_LEFT:
371               if(fire == DOWN)
372                 cursor_x -= KEY_CURSOR_SPEED;
373               else
374                 cursor_x -= KEY_CURSOR_FASTSPEED;
375               break;
376             case SDLK_RIGHT:
377               if(fire == DOWN)
378                 cursor_x += KEY_CURSOR_SPEED;
379               else
380                 cursor_x += KEY_CURSOR_FASTSPEED;
381               break;
382             case SDLK_UP:
383               if(fire == DOWN)
384                 cursor_y -= KEY_CURSOR_SPEED;
385               else
386                 cursor_y -= KEY_CURSOR_FASTSPEED;
387
388               if(cursor_y < 0)
389                 cursor_y = 0;
390               break;
391             case SDLK_DOWN:
392               if(fire == DOWN)
393                 cursor_y += KEY_CURSOR_SPEED;
394               else
395                 cursor_y += KEY_CURSOR_FASTSPEED;
396
397               if(cursor_y > screen->h-32)
398                 cursor_y = screen->h-32;
399               break;
400             case SDLK_LCTRL:
401               fire =UP;
402               break;
403             case SDLK_F1:
404               le_showhelp();
405               break;
406             case SDLK_F2:
407               level_save(&le_current_level,"test",le_level);
408               gameloop("test",le_level, ST_GL_TEST);
409               menu_set_current(&leveleditor_menu);
410               arrays_init();
411               level_load_gfx(&le_current_level);
412               loadshared();
413               le_activate_bad_guys();
414               break;
415             case SDLK_HOME:
416               cursor_x = 0;
417               break;
418             case SDLK_END:
419               cursor_x = (le_current_level.width * 32) - 32;
420               break;
421             case SDLK_PAGEUP:
422               cursor_x -= PAGE_CURSOR_SPEED;
423               break;
424             case SDLK_PAGEDOWN:
425               cursor_x += PAGE_CURSOR_SPEED;
426               break;
427             case SDLK_F9:
428               le_show_grid = !le_show_grid;
429               break;
430             case SDLK_PERIOD:
431               le_change(cursor_x, cursor_y, '.');
432               break;
433             case SDLK_a:
434               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
435                 le_change(cursor_x, cursor_y, 'A');
436               else
437                 le_change(cursor_x, cursor_y, 'a');
438               break;
439             case SDLK_b:
440               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
441                 le_change(cursor_x, cursor_y, 'B');
442               break;
443             case SDLK_c:
444               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
445                 le_change(cursor_x, cursor_y, 'C');
446               else
447                 le_change(cursor_x, cursor_y, 'c');
448               break;
449             case SDLK_d:
450               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
451                 le_change(cursor_x, cursor_y, 'D');
452               else
453                 le_change(cursor_x, cursor_y, 'd');
454               break;
455             case SDLK_e:
456               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
457                 le_change(cursor_x, cursor_y, 'E');
458               else
459                 le_change(cursor_x, cursor_y, 'e');
460               break;
461             case SDLK_f:
462               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
463                 le_change(cursor_x, cursor_y, 'F');
464               else
465                 le_change(cursor_x, cursor_y, 'f');
466               break;
467             case SDLK_g:
468               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
469                 le_change(cursor_x, cursor_y, 'G');
470               else
471                 le_change(cursor_x, cursor_y, 'g');
472               break;
473             case SDLK_h:
474               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
475                 le_change(cursor_x, cursor_y, 'H');
476               else
477                 le_change(cursor_x, cursor_y, 'h');
478               break;
479             case SDLK_i:
480               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
481                 le_change(cursor_x, cursor_y, 'I');
482               else
483                 le_change(cursor_x, cursor_y, 'i');
484               break;
485             case SDLK_j:
486               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
487                 le_change(cursor_x, cursor_y, 'J');
488               else
489                 le_change(cursor_x, cursor_y, 'j');
490               break;
491             case SDLK_x:
492               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
493                 le_change(cursor_x, cursor_y, 'X');
494               else
495                 le_change(cursor_x, cursor_y, 'x');
496               break;
497             case SDLK_y:
498               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
499                 le_change(cursor_x, cursor_y, 'Y');
500               else
501                 le_change(cursor_x, cursor_y, 'y');
502               break;
503             case SDLK_LEFTBRACKET:
504               le_change(cursor_x, cursor_y, '[');
505               break;
506             case SDLK_RIGHTBRACKET:
507               le_change(cursor_x, cursor_y, ']');
508               break;
509             case SDLK_HASH:
510             case SDLK_3:
511               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
512                 le_change(cursor_x, cursor_y, '#');
513               break;
514             case SDLK_DOLLAR:
515             case SDLK_4:
516               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
517                 le_change(cursor_x, cursor_y, '$');
518               break;
519             case SDLK_BACKSLASH:
520               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
521                 le_change(cursor_x, cursor_y, '|');
522               else
523                 le_change(cursor_x, cursor_y, '\\');
524               break;
525             case SDLK_CARET:
526               le_change(cursor_x, cursor_y, '^');
527               break;
528             case SDLK_AMPERSAND:
529             case SDLK_6:
530               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
531                 le_change(cursor_x, cursor_y, '&');
532               break;
533             case SDLK_EQUALS:
534             case SDLK_0:
535               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
536                 le_change(cursor_x, cursor_y, '=');
537               else              /* let's add a bad guy */
538                 le_change(cursor_x, cursor_y, '0');
539
540               add_bad_guy((((int)cursor_x/32)*32), (((int)cursor_y/32)*32), BAD_BSOD);
541               break;
542             case SDLK_1:
543               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
544                 le_change(cursor_x, cursor_y, '!');
545               else              /* let's add a bad guy */
546                 le_change(cursor_x, cursor_y, '1');
547
548               add_bad_guy((((int)cursor_x/32)*32), (((int)cursor_y/32)*32), BAD_LAPTOP);
549               break;
550             case SDLK_2:
551               le_change(cursor_x, cursor_y, '2');
552
553               add_bad_guy((((int)cursor_x/32)*32), (((int)cursor_y/32)*32), BAD_MONEY);
554               break;
555             case SDLK_PLUS:
556               if(keymod == KMOD_LSHIFT || keymod == KMOD_RSHIFT || keymod == KMOD_CAPS)
557                 le_change(cursor_x, cursor_y, '*');
558               break;
559             default:
560               break;
561             }
562           break;
563         case SDL_KEYUP: // key released
564           switch(event.key.keysym.sym)
565             {
566             case SDLK_LCTRL:
567               fire = DOWN;
568               break;
569             default:
570               break;
571             }
572           break;
573         case SDL_MOUSEBUTTONDOWN:
574           if(event.button.button == SDL_BUTTON_LEFT)
575             {
576               le_mouse_pressed = YES;
577             }
578           break;
579         case SDL_MOUSEBUTTONUP:
580           if(event.button.button == SDL_BUTTON_LEFT)
581             {
582               le_mouse_pressed = NO;
583             }
584           break;
585         case SDL_MOUSEMOTION:
586           if(!show_menu)
587             {
588               x = event.motion.x;
589               y = event.motion.y;
590
591               cursor_x = ((int)(pos_x + x) / 32) * 32;
592               cursor_y = ((int) y / 32) * 32;
593             }
594           break;
595         case SDL_QUIT:  // window closed
596           done = DONE_QUIT;
597           break;
598         default:
599           break;
600         }
601     }
602
603   if(le_mouse_pressed)
604     {
605       le_change(cursor_x, cursor_y, le_current_tile);
606       if(button_pressed(&le_test_level_bt,x,y))
607         {
608           level_save(&le_current_level,"test",le_level);
609           gameloop("test",le_level, ST_GL_TEST);
610           menu_set_current(&leveleditor_menu);
611           arrays_init();
612           level_load_gfx(&le_current_level);
613           loadshared();
614           le_activate_bad_guys();
615         }
616     }
617
618 }
619
620 void le_change(float x, float y, unsigned char c)
621 {
622   int i;
623   int xx, yy;
624
625   level_change(&le_current_level,x,y,c);
626
627   yy = ((int)y / 32);
628   xx = ((int)x / 32);
629
630   /* if there is a bad guy over there, remove it */
631   for(i = 0; i < num_bad_guys; ++i)
632     if (bad_guys[i].base.alive)
633       if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32)
634         bad_guys[i].base.alive = NO;
635 }
636
637 void le_showhelp()
638 {
639   SDL_Event event;
640   int i, done;
641   char *text[] = {
642                    "X/x - Brick0",
643                    "Y/y - Brick1",
644                    "A/B/! - Box full",
645                    "a - Box empty",
646                    "C-F - Cloud0",
647                    "c-f - Cloud1",
648                    "G-J - Bkgd0",
649                    "g-j - Bkgd1",
650                    "# - Solid0",
651                    "[ - Solid1",
652                    "= - Solid2",
653                    "] - Solid3",
654                    "$ - Distro",
655                    "^ - Waves",
656                    "* - Poletop",
657                    "| - Pole",
658                    "\\ - Flag",
659                    "& - Water",
660                    "0-2 - BadGuys",
661                    "./Del - Remove tile",
662                    "F9 - Show/Hide Grid",
663                    "Esc - Menu"};
664
665
666   text_drawf(&blue_text, "- Help -", 0, 30, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
667   text_draw(&gold_text, "Keys:", 80, 60, 1, NO_UPDATE);
668
669   for(i = 0; i < sizeof(text)/sizeof(char *); i++)
670     text_draw(&white_text, text[i], 40, 90+(i*16), 1, NO_UPDATE);
671
672   text_drawf(&gold_text, "Press Any Key to Continue", 0, 460, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
673
674   flipscreen();
675
676   done = 0;
677
678   while(done == 0)
679     while(SDL_PollEvent(&event))
680       switch(event.type)
681         {
682         case SDL_MOUSEBUTTONDOWN:               // mouse pressed
683         case SDL_KEYDOWN:               // key pressed
684           done = 1;
685           break;
686         default:
687           break;
688         }
689 }