Implemented --help and --disable-sound (patch by Duong-Khang NGUYEN <neoneurone@users...
[supertux.git] / src / gameloop.c
index 11be5ad..808e142 100644 (file)
@@ -7,7 +7,7 @@
   bill@newbreedsoftware.com
   http://www.newbreedsoftware.com/supertux/
   
-  April 11, 2000 - July 15, 2002
+  April 11, 2000 - December 9, 2003
 */
 
 #include <stdio.h>
 #include <SDL.h>
 #include <SDL_image.h>
 
-#ifndef NOSOUND
-#include <SDL_mixer.h>
-#endif
-
 #ifdef LINUX
 #include <pwd.h>
 #include <sys/types.h>
@@ -34,6 +30,7 @@
 #include "screen.h"
 #include "sound.h"
 #include "setup.h"
+#include "high_scores.h"
 
 
 /* Sound files: */
@@ -54,7 +51,7 @@ enum {
   SND_EXCELLENT,
   SND_COFFEE,
   SND_SHOOT,
-  NUM_SOUNDS
+  SND_LIFEUP
 };
 
 char * soundfilenames[NUM_SOUNDS] = {
@@ -72,34 +69,20 @@ char * soundfilenames[NUM_SOUNDS] = {
   DATA_PREFIX "/sounds/upgrade.wav",
   DATA_PREFIX "/sounds/excellent.wav",
   DATA_PREFIX "/sounds/coffee.wav",
-  DATA_PREFIX "/sounds/shoot.wav"
-};
-
-
-/* Level names: */
-
-char * levelnames[] = {
-  "Antarctica",
-  "Australia",
-  "India",
-  "Egypt",
-  "Greece",
-  "Spain",
-  "Brazil",
-  "America",
-  "Redmond"
+  DATA_PREFIX "/sounds/shoot.wav",
+  DATA_PREFIX "/sounds/lifeup.wav"
 };
 
 
 /* Local variables: */
 
-int score, distros, level, lives, scroll_x,
+int score, highscore, distros, level, lives, scroll_x, next_level,
   tux_dir, tux_size, tux_duck, tux_x, tux_xm, tux_y, tux_ym,
   tux_dying, tux_safe, jumping, jump_counter, frame, score_multiplier,
   tux_frame_main, tux_frame, tux_got_coffee, tux_skidding,
-  super_bkgd_time, time_left, tux_invincible_time,
+  super_bkgd_time, time_left, tux_invincible_time, endpos,
   counting_distros, distro_counter;
-int bkgd_red, bkgd_green, bkgd_blue;
+int bkgd_red, bkgd_green, bkgd_blue, level_width;
 int left, right, up, down, fire, old_fire;
 SDL_Surface * img_brick[2], * img_solid[4], * img_distro[4],
   * img_waves[3], * img_water, * img_pole, * img_poletop, * img_flag[2];
@@ -122,11 +105,7 @@ SDL_Surface * tux_right[3], * tux_left[3],
   * bigcape_right[2], * bigcape_left[2],
   * ducktux_right, * ducktux_left,
   * skidtux_right, * skidtux_left;
-#ifndef NOSOUND
-Mix_Chunk * sounds[NUM_SOUNDS];
-Mix_Music * song;
-#endif
-unsigned char tiles[15][LEVEL_WIDTH + 5];
+unsigned char * tiles[15];
 bouncy_distro_type bouncy_distros[NUM_BOUNCY_DISTROS];
 broken_brick_type broken_bricks[NUM_BROKEN_BRICKS];
 bouncy_brick_type bouncy_bricks[NUM_BOUNCY_BRICKS];
@@ -134,6 +113,8 @@ bad_guy_type bad_guys[NUM_BAD_GUYS];
 floating_score_type floating_scores[NUM_FLOATING_SCORES];
 upgrade_type upgrades[NUM_UPGRADES];
 bullet_type bullets[NUM_BULLETS];
+char song_title[20];
+char levelname[20];
 
 
 /* Local function prototypes: */
@@ -167,6 +148,7 @@ void trybumpbadguy(int x, int y, int sx);
 void add_upgrade(int x, int y, int kind);
 void killtux(int mode);
 void add_bullet(int x, int y, int dir, int xm);
+void drawendscreen(void);
 
 
 /* --- GAME LOOP! --- */
@@ -194,6 +176,7 @@ int gameloop(void)
   loadlevel();
   loadlevelgfx();
   loadlevelsong();
+  highscore = load_hs();
   
   
   /* --- MAIN GAME LOOP!!! --- */
@@ -285,6 +268,10 @@ int gameloop(void)
                {
                  tux_size = !tux_size;
                }
+             else if (key == SDLK_END)
+               {
+                 distros += 50;
+               }
            }
 #ifdef JOY_YES
          else if (event.type == SDL_JOYAXISMOTION)
@@ -331,7 +318,7 @@ int gameloop(void)
       
       /* Handle key and joystick state: */
       
-      if (!tux_dying)
+      if (!tux_dying && !next_level)
        {
          if (right == DOWN && left == UP)
            {
@@ -341,9 +328,9 @@ int gameloop(void)
                      tux_dir == LEFT)
                    {
                      tux_skidding = SKID_TIME;
-#ifndef NOSOUND
+
                      playsound(sounds[SND_SKID]);
-#endif
+
                    }
                  tux_dir = RIGHT;
                }
@@ -395,9 +382,7 @@ int gameloop(void)
                      tux_dir == RIGHT)
                    {
                      tux_skidding = SKID_TIME;
-#ifndef NOSOUND
                      playsound(sounds[SND_SKID]);
-#endif
                    }
                  tux_dir = LEFT;
                }
@@ -441,6 +426,16 @@ int gameloop(void)
                    }
                }
            }
+
+
+         /* End of level? */
+
+         if (tux_x >= endpos && endpos != 0)
+         {
+            /* FIXME: No need to kill Tux to end the level! ;^) */
+           next_level = 1;
+           tux_dying = 1;
+         }
          
          
          /* Jump/jumping? */
@@ -468,12 +463,10 @@ int gameloop(void)
                        {
                          jumping = YES;
                         
-#ifndef NOSOUND
                          if (tux_size == SMALL)
                            playsound(sounds[SND_JUMP]);
                          else
                            playsound(sounds[SND_BIGJUMP]);
-#endif
                        }
                    }
                }
@@ -518,27 +511,58 @@ int gameloop(void)
              else
                tux_duck = NO;
            }
-       } /* !tux_dying */
+       } /* !tux_dying && !next_level */
       else
        {
+          /* Tux either died, or reached the end of a level! */
+               
          tux_ym = tux_ym + GRAVITY;
          
          if (tux_y >= 480)
            {
-#ifndef NOSOUND
              if (use_sound)
                {
                  if (Mix_PlayingMusic())
                    Mix_HaltMusic();
                }
-#endif
+            
+             if (next_level)
+             {
+               /* End of a level! */
+
+               level++;
+               next_level = 0;
+             }
+             else
+             {
+               /* He died :^( */
+                     
+               lives--;
+             }
+
+             
+             /* No more lives!? */
+
+             if (lives < 0)
+             {
+                drawendscreen();
+
+               if (score > highscore)
+                 save_hs(score);
+
+               return(0);
+             }
+             
+             
+             /* Either way, (re-)load the (next) level... */
              
-             lives--;
              loadlevel();
+
+             unloadlevelgfx();
+             loadlevelgfx();
            }
        }
-      
-      
+
       /* Move tux: */
       
       tux_x = tux_x + tux_xm;
@@ -549,15 +573,15 @@ int gameloop(void)
       
       if (tux_x < 0)
        tux_x = 0;
-      else if (tux_x > 320 && scroll_x < ((LEVEL_WIDTH * 32) - 640))
+      else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
        {
          /* Scroll the screen in past center: */
          
          scroll_x = scroll_x + (tux_x - 320);
          tux_x = 320;
          
-         if (scroll_x > ((LEVEL_WIDTH * 32) - 640))
-           scroll_x = ((LEVEL_WIDTH * 32) - 640);
+         if (scroll_x > ((level_width * 32) - 640))
+           scroll_x = ((level_width * 32) - 640);
        }
       else if (tux_x > 608)
        {
@@ -771,9 +795,7 @@ int gameloop(void)
                              if (distro_counter <= 0)
                                change(tux_x, tux_y, scroll_x, 'a');
                              
-#ifndef NOSOUND
                              playsound(sounds[SND_DISTRO]);
-#endif
                              score = score + SCORE_DISTRO;
                              distros++;
                            }
@@ -793,9 +815,7 @@ int gameloop(void)
                              if (distro_counter <= 0)
                                change(tux_x + 31, tux_y, scroll_x, 'a');
                              
-#ifndef NOSOUND
                              playsound(sounds[SND_DISTRO]);
-#endif
                              score = score + SCORE_DISTRO;
                              distros++;
                            }
@@ -834,6 +854,18 @@ int gameloop(void)
              trygrabdistro(tux_x + 31, tux_y - 32, scroll_x, NO_BOUNCE);
            }
        }
+
+
+      /* Enough distros for a One-up? */
+
+      if (distros >= DISTROS_LIFEUP)
+      {
+       /* FIXME: Play a special sound or flash or both! */
+
+       distros = distros - DISTROS_LIFEUP;
+       lives++;
+        playsound(sounds[SND_LIFEUP]);
+      }
      
 
       /* Keep in-bounds, vertically: */
@@ -1016,12 +1048,29 @@ int gameloop(void)
                          bullets[i].y >= bad_guys[j].y - 4 &&
                          bullets[i].y <= bad_guys[j].y + 32 + 4)
                        {
+                         /* Kill the bad guy! */
+                               
                          bullets[i].alive = 0;
                          bad_guys[j].dying = FALLING;
                          bad_guys[j].ym = -8;
-#ifndef NOSOUND
+
+
+                         /* Gain some points: */
+
+                         if (bad_guys[j].kind == BAD_BSOD)
+                          {
+                            add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
+                                       50 * score_multiplier);
+                          }
+                          else if (bad_guys[j].kind == BAD_LAPTOP)
+                          {
+                            add_score(bad_guys[j].x - scroll_x, bad_guys[j].y,
+                                         25 * score_multiplier);
+                         }
+
+
+                         /* Play death sound: */
                          playsound(sounds[SND_FALL]);
-#endif
                        }
                    }
                }
@@ -1112,25 +1161,19 @@ int gameloop(void)
                      
                      if (upgrades[i].kind == UPGRADE_MINTS)
                        {
-#ifndef NOSOUND
                           playsound(sounds[SND_EXCELLENT]);
-#endif
                          tux_size = BIG;
                          super_bkgd_time = 8;
                        }
                      else if (upgrades[i].kind == UPGRADE_COFFEE)
                        {
-#ifndef NOSOUND
                          playsound(sounds[SND_COFFEE]);
-#endif
                          tux_got_coffee = YES;
                          super_bkgd_time = 4;
                        }
                      else if (upgrades[i].kind == UPGRADE_HERRING)
                        {
-#ifndef NOSOUND
                          playsound(sounds[SND_HERRING]);
-#endif
                          tux_invincible_time = 200;
                          super_bkgd_time = 4;
                        }
@@ -1259,10 +1302,8 @@ int gameloop(void)
                            {
                              bad_guys[i].dir = !bad_guys[i].dir;
                             
-#ifndef NOSOUND
                              if (bad_guys[i].mode == KICK)
                                playsound(sounds[SND_RICOCHET]);
-#endif
                            }
                        }
                      
@@ -1286,9 +1327,7 @@ int gameloop(void)
                                  
                                  bad_guys[j].dying = FALLING;
                                  bad_guys[j].ym = -8;
-#ifndef NOSOUND
                                  playsound(sounds[SND_FALL]);
-#endif
 
                                  add_score(bad_guys[i].x - scroll_x,
                                            bad_guys[i].y, 100);
@@ -1385,9 +1424,7 @@ int gameloop(void)
                          add_score(bad_guys[i].x - scroll_x, bad_guys[i].y,
                                    50 * score_multiplier);
                          
-#ifndef NOSOUND
                          playsound(sounds[SND_SQUISH]);
-#endif
                        }
                      else if (bad_guys[i].kind == BAD_LAPTOP)
                        {
@@ -1421,9 +1458,7 @@ int gameloop(void)
                                    bad_guys[i].y,
                                    25 * score_multiplier);
                         
-#ifndef NOSOUND
                          /* playsound(sounds[SND_SQUISH]); */
-#endif
                        }
                      else if (bad_guys[i].kind == -1)
                        {
@@ -1485,9 +1520,7 @@ int gameloop(void)
                                    {
                                      bad_guys[i].dying = FALLING;
                                      bad_guys[i].ym = -8;
-#ifndef NOSOUND
                                      playsound(sounds[SND_FALL]);
-#endif
                                    }
                                }
                            }
@@ -1502,9 +1535,7 @@ int gameloop(void)
                            {
                              bad_guys[i].dying = FALLING;
                              bad_guys[i].ym = -8;
-#ifndef NOSOUND
                              playsound(sounds[SND_FALL]);
-#endif
                            }
                        }
                    }
@@ -2066,6 +2097,10 @@ int gameloop(void)
       sprintf(str, "%d", score);
       drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE);
       drawtext(str, 96, 0, letters_gold, NO_UPDATE);
+
+      sprintf(str, "%d", highscore);
+      drawtext("HIGH", 0, 20, letters_blue, NO_UPDATE);
+      drawtext(str, 96, 20, letters_gold, NO_UPDATE);
       
       if (time_left >= 50 || (frame % 10) < 5)
        {
@@ -2086,7 +2121,6 @@ int gameloop(void)
       
       /* Keep playing music: */
     
-#ifndef NOSOUND
       if (use_sound)
         {
           if (!Mix_PlayingMusic())
@@ -2094,7 +2128,6 @@ int gameloop(void)
              Mix_PlayMusic(song, 1);
            }
         }
-#endif
       
       
       /* Pause til next frame: */
@@ -2116,13 +2149,11 @@ int gameloop(void)
     }
   while (!done && !quit);
  
-#ifndef NOSOUND
   if (use_sound)
     {
       if (Mix_PlayingMusic())
         Mix_HaltMusic();
     }
-#endif
   
   unloadlevelgfx();
   unloadlevelsong();
@@ -2136,7 +2167,7 @@ int gameloop(void)
 
 void initgame(void)
 {
-  level = 0;
+  level = 1;
   score = 0;
   distros = 0;
   lives = 3;
@@ -2151,7 +2182,7 @@ void loadlevel(void)
   FILE * fi;
   char * filename;
   char str[80];
-  char line[LEVEL_WIDTH + 5];
+  char * line;
   
   
   /* Reset arrays: */
@@ -2179,8 +2210,9 @@ void loadlevel(void)
 
 
   /* Load data file: */
-  
-  filename = strdup(DATA_PREFIX "/levels/level1.dat");
+  filename = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) + 20));
+  sprintf(filename, "%s/levels/level%d.dat", DATA_PREFIX, level);
   fi = fopen(filename, "r");
   if (fi == NULL)
     {
@@ -2189,18 +2221,51 @@ void loadlevel(void)
     }
   free(filename);
   
-  fgets(line, 10, fi);
-  bkgd_red = atoi(line);
-  fgets(line, 10, fi);
-  bkgd_green= atoi(line);
-  fgets(line, 10, fi);
-  bkgd_blue = atoi(line);
+
+  /* Load header info: */
+
+  /* (Level title) */
+  fgets(str, 20, fi);
+  strcpy(levelname, str);
+
+  /* (Time to beat level) */
+  fgets(str, 10, fi);
+  time_left = atoi(str);
+
+  /* (Song file for this level) */
+  fgets(str, 20, fi);
+  strcpy(song_title, str);
+  
+  /* (Level background color) */
+  fgets(str, 10, fi);
+  bkgd_red = atoi(str);
+  fgets(str, 10, fi);
+  bkgd_green= atoi(str);
+  fgets(str, 10, fi);
+  bkgd_blue = atoi(str);
+
+  /* (Level width) */
+  fgets(str, 10, fi);
+  level_width = atoi(str);
+  
+
+  /* Allocate some space for the line-reading! */
+  
+  line = (char *) malloc(sizeof(char) * (level_width + 5));
+  if (line == NULL)
+  {
+    fprintf(stderr, "Couldn't allocate space to load level data!");
+    exit(1);
+  }
+  
+  
+  /* Load the level lines: */
   
   for (y = 0; y < 15; y++)
     {
-      fgets(line, LEVEL_WIDTH + 5, fi);
+      fgets(line, level_width + 5, fi);
       line[strlen(line) - 1] = '\0';
-      strcpy(tiles[y], line);
+      tiles[y] = strdup(line);
     }
   
   fclose(fi);
@@ -2210,7 +2275,7 @@ void loadlevel(void)
   
   for (y = 0; y < 15; y++)
     {
-      for (x = 0; x < LEVEL_WIDTH; x++)
+      for (x = 0; x < level_width; x++)
        {
          if (tiles[y][x] >= '0' && tiles[y][x] <= '9')
            {
@@ -2263,10 +2328,10 @@ void loadlevel(void)
   
   clearscreen(0, 0, 0);
   
-  sprintf(str, "LEVEL %d", level + 1);
+  sprintf(str, "LEVEL %d", level);
   drawcenteredtext(str, 200, letters_red, NO_UPDATE);
   
-  sprintf(str, "%s", levelnames[level]);
+  sprintf(str, "%s", levelname);
   drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
   
   sprintf(str, "TUX x %d", lives);
@@ -2278,41 +2343,39 @@ void loadlevel(void)
 }
 
 
+/* Load a level-specific graphic... */
+
+SDL_Surface * load_level_image(char * file, int use_alpha)
+{
+  char fname[1024];
+
+  snprintf(fname, 1024, "%s/images/level%d/%s", DATA_PREFIX, level, file);
+
+  return(load_image(fname, use_alpha));
+}
+
+
 /* Load graphics: */
 
 void loadlevelgfx(void)
 {
-  img_brick[0] = load_image(DATA_PREFIX "/images/level1/brick0.png",
-                           IGNORE_ALPHA);
-  img_brick[1] = load_image(DATA_PREFIX "/images/level1/brick1.png",
-                           IGNORE_ALPHA);
-  
-  img_solid[0] = load_image(DATA_PREFIX "/images/level1/solid0.png",
-                           USE_ALPHA);
-  img_solid[1] = load_image(DATA_PREFIX "/images/level1/solid1.png",
-                           USE_ALPHA);
-  img_solid[2] = load_image(DATA_PREFIX "/images/level1/solid2.png",
-                           USE_ALPHA);
-  img_solid[3] = load_image(DATA_PREFIX "/images/level1/solid3.png",
-                           USE_ALPHA);
-
-  img_bkgd[0][0] = load_image(DATA_PREFIX "/images/level1/bkgd-00.png",
-                              USE_ALPHA);
-  img_bkgd[0][1] = load_image(DATA_PREFIX "/images/level1/bkgd-01.png",
-                              USE_ALPHA);
-  img_bkgd[0][2] = load_image(DATA_PREFIX "/images/level1/bkgd-02.png",
-                              USE_ALPHA);
-  img_bkgd[0][3] = load_image(DATA_PREFIX "/images/level1/bkgd-03.png",
-                              USE_ALPHA);
-
-  img_bkgd[1][0] = load_image(DATA_PREFIX "/images/level1/bkgd-10.png",
-                              USE_ALPHA);
-  img_bkgd[1][1] = load_image(DATA_PREFIX "/images/level1/bkgd-11.png",
-                              USE_ALPHA);
-  img_bkgd[1][2] = load_image(DATA_PREFIX "/images/level1/bkgd-12.png",
-                              USE_ALPHA);
-  img_bkgd[1][3] = load_image(DATA_PREFIX "/images/level1/bkgd-13.png",
-                              USE_ALPHA);
+  img_brick[0] = load_level_image("brick0.png", IGNORE_ALPHA);
+  img_brick[1] = load_level_image("brick1.png", IGNORE_ALPHA);
+  
+  img_solid[0] = load_level_image("solid0.png", USE_ALPHA);
+  img_solid[1] = load_level_image("solid1.png", USE_ALPHA);
+  img_solid[2] = load_level_image("solid2.png", USE_ALPHA);
+  img_solid[3] = load_level_image("solid3.png", USE_ALPHA);
+
+  img_bkgd[0][0] = load_level_image("bkgd-00.png", USE_ALPHA);
+  img_bkgd[0][1] = load_level_image("bkgd-01.png", USE_ALPHA);
+  img_bkgd[0][2] = load_level_image("bkgd-02.png", USE_ALPHA);
+  img_bkgd[0][3] = load_level_image("bkgd-03.png", USE_ALPHA);
+
+  img_bkgd[1][0] = load_level_image("bkgd-10.png", USE_ALPHA);
+  img_bkgd[1][1] = load_level_image("bkgd-11.png", USE_ALPHA);
+  img_bkgd[1][2] = load_level_image("bkgd-12.png", USE_ALPHA);
+  img_bkgd[1][3] = load_level_image("bkgd-13.png", USE_ALPHA);
 }
 
 
@@ -2320,9 +2383,16 @@ void loadlevelgfx(void)
 
 void loadlevelsong(void)
 {
-#ifndef NOSOUND
+  char * song_path;
+
+  song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
+                                             strlen(song_title) + 8));
+
+  sprintf(song_path, "%s/music/%s", DATA_PREFIX, song_title);
+  
   song = load_song(DATA_PREFIX "/music/ji_turn.it");
-#endif
+
+  free(song_path);
 }
 
 
@@ -2349,12 +2419,10 @@ void unloadlevelgfx(void)
 
 void unloadlevelsong(void)
 {
-#ifndef NOSOUND
   if (use_sound)
     {
       Mix_FreeMusic(song);
     }
-#endif
 }
 
 
@@ -2362,9 +2430,7 @@ void unloadlevelsong(void)
 
 void loadshared(void)
 {
-#ifndef NOSOUND
   int i;
-#endif
   
   
   /* Tuxes: */
@@ -2684,13 +2750,12 @@ void loadshared(void)
   
   /* Sound effects: */
   
-#ifndef NOSOUND
   if (use_sound)
     {
       for (i = 0; i < NUM_SOUNDS; i++)
        sounds[i] = load_sound(soundfilenames[i]);
+       
     }
-#endif
 }
 
 
@@ -2780,13 +2845,11 @@ void unloadshared(void)
   
   SDL_FreeSurface(img_golden_herring);
 
-#ifndef NOSOUND
   if (use_sound)
     {
       for (i = 0; i < NUM_SOUNDS; i++)
         Mix_FreeChunk(sounds[i]);
     }
-#endif
 }
 
 
@@ -2840,7 +2903,13 @@ void drawshape(int x, int y, unsigned char c)
   else if (c == '*')
     drawimage(img_poletop, x, y, NO_UPDATE);
   else if (c == '|')
+  {
     drawimage(img_pole, x, y, NO_UPDATE);
+
+    /* Mark this as the end position of the level! */
+
+    endpos = x;
+  }
   else if (c == '\\')
     {
       z = (frame / 3) % 2;
@@ -2862,7 +2931,7 @@ unsigned char shape(int x, int y, int sx)
   yy = (y / 32);
   xx = ((x + sx) / 32);
   
-  if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= LEVEL_WIDTH)
+  if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
     c = tiles[yy][xx];
   else
     c = '.';
@@ -2970,7 +3039,7 @@ void change(int x, int y, int sx, unsigned char c)
   yy = (y / 32);
   xx = ((x + sx) / 32);
   
-  if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= LEVEL_WIDTH)
+  if (yy >= 0 && yy <= 15 && xx >= 0 && xx <= level_width)
     tiles[yy][xx] = c;
 }
 
@@ -2997,9 +3066,7 @@ void trybreakbrick(int x, int y, int sx)
          if (distro_counter <= 0)
           change(x, y, sx, 'a');
         
-#ifndef NOSOUND
          playsound(sounds[SND_DISTRO]);
-#endif
          score = score + SCORE_DISTRO;
          distros++;
        }
@@ -3019,9 +3086,7 @@ void trybreakbrick(int x, int y, int sx)
       
       /* Get some score: */
       
-#ifndef NOSOUND
       playsound(sounds[SND_BRICK]);
-#endif
       score = score + SCORE_BRICK;
     }
 }
@@ -3034,9 +3099,7 @@ void bumpbrick(int x, int y, int sx)
   add_bouncy_brick(((x + sx + 1) / 32) * 32,
                   (y / 32) * 32);
   
-#ifndef NOSOUND
   playsound(sounds[SND_BRICK]);
-#endif
 }
 
 
@@ -3053,9 +3116,7 @@ void tryemptybox(int x, int y, int sx)
          add_bouncy_distro(((x + sx + 1) / 32) * 32,
                            (y / 32) * 32 - 32);
          
-#ifndef NOSOUND
          playsound(sounds[SND_DISTRO]);
-#endif
          score = score + SCORE_DISTRO;
          distros++;
        }
@@ -3080,9 +3141,7 @@ void tryemptybox(int x, int y, int sx)
                          UPGRADE_COFFEE);
            }
          
-#ifndef NOSOUND
          playsound(sounds[SND_UPGRADE]);
-#endif
        }
       else if (shape(x, y, sx) == '!')
        {
@@ -3107,9 +3166,7 @@ void trygrabdistro(int x, int y, int sx, int bounciness)
   if (shape(x, y, sx) == '$')
     {
       change(x, y, sx, '.');
-#ifndef NOSOUND
       playsound(sounds[SND_DISTRO]);
-#endif
       
       if (bounciness == BOUNCE)
        {
@@ -3295,9 +3352,7 @@ void trybumpbadguy(int x, int y, int sx)
            {
              bad_guys[i].dying = FALLING;
              bad_guys[i].ym = -8;
-#ifndef NOSOUND
              playsound(sounds[SND_FALL]);
-#endif
            }
        }
     }
@@ -3313,9 +3368,7 @@ void trybumpbadguy(int x, int y, int sx)
        {
          upgrades[i].xm = -upgrades[i].xm;
          upgrades[i].ym = -8;
-#ifndef NOSOUND
          playsound(sounds[SND_BUMP_UPGRADE]);
-#endif
        }
     }
 }
@@ -3354,9 +3407,7 @@ void killtux(int mode)
 {
   tux_ym = -16;
  
-#ifndef NOSOUND
   playsound(sounds[SND_HURT]);
-#endif
  
   if (tux_dir == RIGHT)
     tux_xm = -8;
@@ -3411,8 +3462,26 @@ void add_bullet(int x, int y, int dir, int xm)
       bullets[found].y = y;
       bullets[found].ym = BULLET_STARTING_YM;
       
-#ifndef NOSOUND
       playsound(sounds[SND_SHOOT]);
-#endif
     }
 }
+
+
+void drawendscreen(void)
+{
+  char str[80];
+  
+  clearscreen(0, 0, 0);
+
+  drawcenteredtext("GAMEOVER", 200, letters_red, NO_UPDATE);
+
+  sprintf(str, "SCORE: %d", score);
+  drawcenteredtext(str, 224, letters_gold, NO_UPDATE);
+
+  sprintf(str, "DISTROS: %d", distros);
+  drawcenteredtext(str, 256, letters_blue, NO_UPDATE);
+
+  SDL_Flip(screen);
+  SDL_Delay(2000);
+}
+