ye another sound patch from Duong-Khang NGUYEN <neoneurone@users.sf.net>.
authorTobias Gläßer <tobi.web@gmx.de>
Thu, 25 Dec 2003 20:45:08 +0000 (20:45 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Thu, 25 Dec 2003 20:45:08 +0000 (20:45 +0000)
Moreover you can see tux's lives now! ;) And the highscore file is now found in $HOME/.supertux/

SVN-Revision: 44

src/gameloop.c
src/globals.h
src/high_scores.c
src/menu.c
src/setup.c
src/sound.c
src/sound.h

index 56aad9c..86ae816 100644 (file)
@@ -105,7 +105,7 @@ SDL_Surface * tux_right[3], * tux_left[3],
 * cape_right[2], * cape_left[2],
 * bigcape_right[2], * bigcape_left[2],
 * ducktux_right, * ducktux_left,
-* skidtux_right, * skidtux_left;
+* skidtux_right, * skidtux_left, * tux_life;
 SDL_Event event;
 SDL_Rect src, dest;
 SDLKey key;
@@ -133,6 +133,7 @@ void unloadlevelsong(void);
 void loadshared(void);
 void unloadshared(void);
 void drawshape(int x, int y, unsigned char c);
+void savegame(void);
 unsigned char shape(int x, int y, int sx);
 int issolid(int x, int y, int sx);
 int isbrick(int x, int y, int sx);
@@ -176,10 +177,10 @@ void game_event(void)
 
           key = event.key.keysym.sym;
 
-         /* Check for menu-events, if the menu is shown */
+          /* Check for menu-events, if the menu is shown */
           if(show_menu)
             menu_event(key);
-         
+
           if (key == SDLK_ESCAPE)
             {
               /* Escape: Open/Close the menu: */
@@ -555,9 +556,9 @@ int game_action(void)
               if (score > highscore)
                 save_hs(score);
 
-             unloadlevelgfx();
+              unloadlevelgfx();
               unloadlevelsong();
-              unloadshared();        
+              unloadshared();
               return(0);
             } /* if (lives < 0) */
         }
@@ -2150,6 +2151,14 @@ void game_draw()
   drawtext("DISTROS", 480, 0, letters_blue, NO_UPDATE);
   drawtext(str, 608, 0, letters_gold, NO_UPDATE);
 
+  drawtext("LIVES", 480, 20, letters_blue, NO_UPDATE);
+
+  for(i=0; i < lives; ++i)
+    {
+      drawimage(tux_life,565+(18*i),20,NO_UPDATE);
+    }
+  /*drawtext(str, 608, 0, letters_gold, NO_UPDATE);*/
+
   if(game_pause)
     drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
 
@@ -2874,6 +2883,10 @@ void loadshared(void)
   img_distro[3] = load_image(DATA_PREFIX "/images/shared/distro-3.png",
                              USE_ALPHA);
 
+  /* Tux life: */
+
+  tux_life = load_image(DATA_PREFIX "/images/shared/tux-life.png",
+                        USE_ALPHA);
 
   /* Herring: */
 
@@ -3655,4 +3668,5 @@ void drawresultscreen(void)
   sleep(2);
 }
 
-
+void savegame(void)
+{}
index b7b4937..482ae16 100644 (file)
@@ -23,6 +23,9 @@ int use_joystick, use_fullscreen;
 
 int game_started;
 
+/* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
+char *st_dir, *st_save_dir;
+
 #ifdef JOY_YES
 SDL_Joystick * js;
 #endif
index 6112b6f..6cf9ab4 100644 (file)
@@ -1,65 +1,59 @@
 /*
-
   by Adam Czachorowski
   gislan@o2.pl
-
 */
 
 /* Open the highscore file: */
 
-# include <string.h>
-# include <stdlib.h>
+#include <string.h>
+#include <stdlib.h>
 
-# include "high_scores.h"
+#include "globals.h"
+#include "high_scores.h"
 
 FILE * opendata(char * mode)
 {
-  char * filename, * home;
+  char * filename;
   FILE * fi;
 
 
 #ifdef LINUX
-  /* Get home directory (from $HOME variable)... if we can't determine it,
-     use the current directory ("."): */
-
-  if (getenv("HOME") != NULL)
-    home = getenv("HOME");
-  else
-    home = ".";
-
 
   /* Create the buffer for the filename: */
 
-  filename = (char *) malloc(sizeof(char) * (strlen(home) +
-                                             strlen("/.supertux") + 1));
+  filename = (char *) malloc(sizeof(char) * (strlen(st_dir) +
+                             strlen("/highscore") + 1));
 
-  strcpy(filename, home);
+  strcpy(filename, st_dir);
   /* Open the high score file: */
 
-      strcat(filename, "/.supertux");
+  strcat(filename, "/highscore");
 #else
-      filename = "supertux.dat";
-#endif
 
+  filename = "st_highscore.dat";
+#endif
 
-      /* Try opening the file: */
 
-      fi = fopen(filename, mode);
+  /* Try opening the file: */
 
-      if (fi == NULL)
-       {
-         fprintf(stderr, "Warning: I could not open the high score file ");
+  fi = fopen(filename, mode);
 
-         if (strcmp(mode, "r") == 0)
-           fprintf(stderr, "for read!!!\n");
-         else if (strcmp(mode, "w") == 0)
-           fprintf(stderr, "for write!!!\n");
+  if (fi == NULL)
+    {
+      fprintf(stderr, "Warning: I could not open the high score file ");
 
-       }
+      if (strcmp(mode, "r") == 0)
+        fprintf(stderr, "for read!!!\n");
+      else if (strcmp(mode, "w") == 0)
+        fprintf(stderr, "for write!!!\n");
 
-      return(fi);
     }
 
+  return(fi);
+}
+
 /* Load data from high score file: */
 
 int load_hs(void)
@@ -90,7 +84,7 @@ int load_hs(void)
 
                   if (score == 0)
                     score = 100;
-               }
+                }
             }
         }
       while (!feof(fi));
@@ -110,7 +104,7 @@ void save_hs(int score)
   fi = opendata("w");
   if (fi != NULL)
     {
-      fprintf(fi, "# Supertux data file\n\n");
+      fprintf(fi, "# Supertux highscore file\n\n");
 
       fprintf(fi, "highscore=%d\n", score);
 
index d86e79e..03401fa 100644 (file)
@@ -147,50 +147,61 @@ int drawmenu(void)
             drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE);
         }
 
-       
-      if(menuitem == 1)
+      if (audio_device == YES)
         {
-          if(use_sound)
-            drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE);
-          else
-            drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
-          if(menuaction == MN_HIT) /* Disable/Enable sound */
+          if(menuitem == 1)
             {
               if(use_sound)
-                {
-                  if(playing_music())
-                    halt_music();
-                  use_sound = 0;
-                }
+                drawcenteredtext("Sound ON", 224, letters_red, NO_UPDATE);
               else
+                drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
+              if(menuaction == MN_HIT) /* Disable/Enable sound */
                 {
-                  use_sound = 1;
-                  if (playing_music())
+                  if(use_sound)
+                    {
+                      if(playing_music())
+                        halt_music();
+                      use_sound = 0;
+                    }
+                  else
                     {
-                      switch (current_music)
+                      use_sound = 1;
+                      if (playing_music())
                         {
-                        case LEVEL_MUSIC:
-                          play_music(level_song, 1);
-                          break;
-                        case HERRING_MUSIC:
-                          play_music(herring_song, 1);
-                          break;
-                        case HURRYUP_MUSIC: // keep the compiler happy
-                        case NO_MUSIC:      // keep the compiler happy for the moment :-)
-                        {}
-                          /*default:*/
+                          switch (current_music)
+                            {
+                            case LEVEL_MUSIC:
+                              play_music(level_song, 1);
+                              break;
+                            case HERRING_MUSIC:
+                              play_music(herring_song, 1);
+                              break;
+                            case HURRYUP_MUSIC: // keep the compiler happy
+                            case NO_MUSIC:      // keep the compiler happy for the moment :-)
+                            {}
+
+                              /*default:*/
+                            }
                         }
                     }
+                  menu_change = YES;
                 }
-               menu_change = YES;
+            }
+          else
+            {
+              if(use_sound)
+                drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
+              else
+                drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
             }
         }
-      else
+      else  /* if audio_device != YES */
         {
-          if(use_sound)
-            drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
+          /* let the user move over the deactivated option */
+          if (menuitem == 1)
+            drawcenteredtext("Sound OFF", 224, letters_red, NO_UPDATE);
           else
-            drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
+            drawcenteredtext("Sound OFF", 224, letters_black, NO_UPDATE);
         }
 
       if(menuitem == 2)
@@ -240,7 +251,7 @@ void menu_event(SDLKey key)
       menuaction = MN_HIT;
       menu_change = YES;
     }
-    
+
   /* FIXME: NO JOYSTICK SUPPORT */
   /*#ifdef JOY_YES
   else if (event.type == SDL_JOYBUTTONDOWN)
index da816ac..0dfeb7e 100644 (file)
@@ -21,6 +21,7 @@
 #ifdef LINUX
 #include <pwd.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <ctype.h>
 #endif
 
@@ -30,7 +31,6 @@
 #include "screen.h"
 #include "sound.h"
 
-
 /* Local function prototypes: */
 
 void seticon(void);
@@ -41,13 +41,38 @@ void usage(char * prog, int ret);
 
 void st_setup(void)
 {
+
+  /* Set SuperTux configuration and save directories
+
+  /* Get home directory (from $HOME variable)... if we can't determine it,
+     use the current directory ("."): */
+  char *home;
+  if (getenv("HOME") != NULL)
+    home = getenv("HOME");
+  else
+    home = ".";
+
+  st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
+                           strlen("/.supertux") + 1));
+  strcpy(st_dir, home);
+  strcat(st_dir, "/.supertux");
+
+  st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
+
+  strcpy(st_save_dir,st_dir);
+  strcpy(st_save_dir,"/save");
+
+  /* Create them. In the case they exist it won't destroy anything. */
+  mkdir(st_dir, 0755);
+  mkdir(st_save_dir, 0755);
+
   /* Seed random number generator: */
-  
+
   srand(SDL_GetTicks());
-  
-  
+
+
   /* Init SDL Video: */
-  
+
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
     {
       fprintf(stderr,
@@ -59,49 +84,49 @@ void st_setup(void)
 
 
   /* Init Joystick: */
-  
+
 #ifdef JOY_YES
   use_joystick = YES;
-  
+
   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
     {
       fprintf(stderr, "Warning: I could not initialize joystick!\n"
               "The Simple DirectMedia error that occured was:\n"
               "%s\n\n", SDL_GetError());
-      
+
       use_joystick = NO;
     }
   else
     {
       /* Open joystick: */
-      
+
       if (SDL_NumJoysticks() <= 0)
         {
           fprintf(stderr, "Warning: No joysticks are available.\n");
-          
+
           use_joystick = NO;
         }
       else
         {
           js = SDL_JoystickOpen(0);
-          
+
           if (js == NULL)
             {
               fprintf(stderr, "Warning: Could not open joystick 1.\n"
                       "The Simple DirectMedia error that occured was:\n"
                       "%s\n\n", SDL_GetError());
-              
+
               use_joystick = NO;
             }
           else
             {
               /* Check for proper joystick configuration: */
-              
+
               if (SDL_JoystickNumAxes(js) < 2)
                 {
                   fprintf(stderr,
                           "Warning: Joystick does not have enough axes!\n");
-                  
+
                   use_joystick = NO;
                 }
               else
@@ -111,7 +136,7 @@ void st_setup(void)
                       fprintf(stderr,
                               "Warning: "
                               "Joystick does not have enough buttons!\n");
-                      
+
                       use_joystick = NO;
                     }
                 }
@@ -119,41 +144,53 @@ void st_setup(void)
         }
     }
 #endif
-  
-  
-  /* Init SDL Audio: */
-  
-  if (use_sound == YES)
+
+
+
+
+  /* Init SDL Audio silently even if --disable-sound : */
+
+  if (audio_device == YES)
     {
       if (SDL_Init(SDL_INIT_AUDIO) < 0)
         {
-          fprintf(stderr,
-                  "\nWarning: I could not initialize audio!\n"
-                  "The Simple DirectMedia error that occured was:\n"
-                  "%s\n\n", SDL_GetError());
-          use_sound = NO;
+          /* only print out message if sound was not disabled at command-line */
+          if (use_sound == YES)
+            {
+              fprintf(stderr,
+                      "\nWarning: I could not initialize audio!\n"
+                      "The Simple DirectMedia error that occured was:\n"
+                      "%s\n\n", SDL_GetError());
+              use_sound = NO;
+            }
+          audio_device = NO;
         }
     }
-  
-  
-  /* Open sound: */
-  
-  if (use_sound == YES)
+
+
+  /* Open sound silently regarless the value of "use_sound": */
+
+  if (audio_device == YES)
     {
       if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
         {
-          fprintf(stderr,
-                  "\nWarning: I could not set up audio for 44100 Hz "
-                  "16-bit stereo.\n"
-                  "The Simple DirectMedia error that occured was:\n"
-                  "%s\n\n", SDL_GetError());
-          use_sound = NO;
+          /* only print out message if sound was not disabled at command-line */
+          if (use_sound == YES)
+            {
+              fprintf(stderr,
+                      "\nWarning: I could not set up audio for 44100 Hz "
+                      "16-bit stereo.\n"
+                      "The Simple DirectMedia error that occured was:\n"
+                      "%s\n\n", SDL_GetError());
+              use_sound = NO;
+            }
+          audio_device = NO;
         }
     }
 
 
   /* Open display: */
-  
+
   if (use_fullscreen == YES)
     {
       screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN) ; /* | SDL_HWSURFACE); */
@@ -167,11 +204,11 @@ void st_setup(void)
           use_fullscreen = NO;
         }
     }
-  
+
   if (use_fullscreen == NO)
     {
       screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
-      
+
       if (screen == NULL)
         {
           fprintf(stderr,
@@ -181,30 +218,30 @@ void st_setup(void)
           exit(1);
         }
     }
-  
-  
+
+
   /* Load global images: */
-  
+
   letters_black = load_image(DATA_PREFIX "/images/status/letters-black.png",
-                            USE_ALPHA);
+                             USE_ALPHA);
 
   letters_gold = load_image(DATA_PREFIX "/images/status/letters-gold.png",
-                            USE_ALPHA);
+                            USE_ALPHA);
 
   letters_blue = load_image(DATA_PREFIX "/images/status/letters-blue.png",
-                            USE_ALPHA);
+                            USE_ALPHA);
 
   letters_red = load_image(DATA_PREFIX "/images/status/letters-red.png",
-                          USE_ALPHA);
-  
-  
+                           USE_ALPHA);
+
+
   /* Set icon image: */
-  
+
   seticon();
-  
-  
+
+
   /* Set window manager stuff: */
-  
+
   SDL_WM_SetCaption("Super Tux", "Super Tux");
 }
 
@@ -234,10 +271,10 @@ void seticon(void)
   int masklen;
   Uint8 * mask;
   SDL_Surface * icon;
-  
-  
+
+
   /* Load icon into a surface: */
-  
+
   icon = IMG_Load(DATA_PREFIX "/images/icon.png");
   if (icon == NULL)
     {
@@ -247,22 +284,22 @@ void seticon(void)
               "%s\n\n", DATA_PREFIX "images/icon.png", SDL_GetError());
       exit(1);
     }
-  
-  
+
+
   /* Create mask: */
-  
+
   masklen = (((icon -> w) + 7) / 8) * (icon -> h);
   mask = malloc(masklen * sizeof(Uint8));
   memset(mask, 0xFF, masklen);
-  
-  
+
+
   /* Set icon: */
-  
+
   SDL_WM_SetIcon(icon, mask);
-  
-  
+
+
   /* Free icon surface & mask: */
-  
+
   free(mask);
   SDL_FreeSurface(icon);
 }
@@ -273,86 +310,92 @@ void seticon(void)
 void parseargs(int argc, char * argv[])
 {
   int i;
-  
-  
+
+
   /* Set defaults: */
-  
+
   use_fullscreen = NO;
-  #ifndef NOSOUND
+#ifndef NOSOUND
+
   use_sound = YES;
-  #else
+  audio_device = YES;
+#else
+
   use_sound = NO;
-  #endif
-  
+  audio_device = NO;
+#endif
+
   /* Parse arguments: */
-  
+
   for (i = 1; i < argc; i++)
     {
       if (strcmp(argv[i], "--fullscreen") == 0 ||
-         strcmp(argv[i], "-f") == 0)
-       {
-         /* Use full screen: */
-         
-         use_fullscreen = YES;
-       }
+          strcmp(argv[i], "-f") == 0)
+        {
+          /* Use full screen: */
+
+          use_fullscreen = YES;
+        }
       else if (strcmp(argv[i], "--usage") == 0)
-       {
-         /* Show usage: */
-         
-         usage(argv[0], 0);
-       }
+        {
+          /* Show usage: */
+
+          usage(argv[0], 0);
+        }
       else if (strcmp(argv[i], "--version") == 0)
-       {
-         /* Show version: */
-         
-         printf("Super Tux - version " VERSION "\n");
-         exit(0);
-       }
-       else if (strcmp(argv[i], "--disable-sound") == 0)
-       {
-         /* Disable the compiled in sound & music feature */
- #ifndef NOSOUND
-         printf("Sounds and music disabled \n");
-         use_sound = NO;
- #else
-         printf("Sounds and music feature is not compiled in \n");
- #endif
-       }
+        {
+          /* Show version: */
+
+          printf("Super Tux - version " VERSION "\n");
+          exit(0);
+        }
+      else if (strcmp(argv[i], "--disable-sound") == 0)
+        {
+          /* Disable the compiled in sound & music feature */
+#ifndef NOSOUND
+          printf("Sounds and music disabled \n");
+          use_sound = NO;
+#else
+
+          printf("Sounds and music feature is not compiled in \n");
+#endif
+
+        }
       else if (strcmp(argv[i], "--help") == 0)
-               /* Show help: */
-         printf("Super Tux " VERSION "\n\n");
-         printf("----------  Command-line options  ----------\n\n");
-           printf("  --disable-sound     - If sound support was compiled in,  this will\n                        disable it for this session of the game.\n\n");
-         printf("  --fullscreen        - Run in fullscreen mode.\n\n");
-         printf("  --help              - Display a help message summarizing command-line\n                        options, license and game controls.\n\n");
-         printf("  --usage             - Display a brief message summarizing command-line options.\n\n");
-         printf("  --version           - Display the version of SuperTux you're running.\n\n\n");
-         printf("----------          License       ----------\n\n");
-         printf("  This program comes with ABSOLUTELY NO WARRANTY.\n");
-         printf("  This is free software, and you are welcome to redistribute\n");
-         printf("  or modify it under certain conditions. See the file \n");
-         printf("  \"COPYING.txt\" for more details.\n\n\n");
-         printf("----------      Game controls     ----------\n\n");
-         printf("  Please see the file \"README.txt\"\n\n");
-         exit(0);
-      }
+        {        /* Show help: */
+
+          printf("Super Tux " VERSION "\n\n");
+
+          printf("----------  Command-line options  ----------\n\n");
+
+          printf("  --disable-sound     - If sound support was compiled in,  this will\n                        disable it for this session of the game.\n\n");
+
+          printf("  --fullscreen        - Run in fullscreen mode.\n\n");
+
+          printf("  --help              - Display a help message summarizing command-line\n                        options, license and game controls.\n\n");
+
+          printf("  --usage             - Display a brief message summarizing command-line options.\n\n");
+
+          printf("  --version           - Display the version of SuperTux you're running.\n\n\n");
+
+
+          printf("----------          License       ----------\n\n");
+          printf("  This program comes with ABSOLUTELY NO WARRANTY.\n");
+          printf("  This is free software, and you are welcome to redistribute\n");
+          printf("  or modify it under certain conditions. See the file \n");
+          printf("  \"COPYING.txt\" for more details.\n\n\n");
+
+          printf("----------      Game controls     ----------\n\n");
+          printf("  Please see the file \"README.txt\"\n\n");
+
+          exit(0);
+        }
       else
-       {
-         /* Unknown - complain! */
-         
-         usage(argv[0], 1);
-       }
+        {
+          /* Unknown - complain! */
+
+          usage(argv[0], 1);
+        }
     }
 }
 
@@ -362,22 +405,22 @@ void parseargs(int argc, char * argv[])
 void usage(char * prog, int ret)
 {
   FILE * fi;
-  
-  
+
+
   /* Determine which stream to write to: */
-  
+
   if (ret == 0)
     fi = stdout;
   else
     fi = stderr;
-  
-  
+
+
   /* Display the usage message: */
-  
+
   fprintf(fi, "Usage: %s [--fullscreen] | [--disable-sound] |  [--usage | --help | --version]\n",
-         prog);
-  
-  
+          prog);
+
+
   /* Quit! */
 
   exit(ret);
index 0912015..f00143d 100644 (file)
 
 int open_audio (int frequency, Uint16 format, int channels, int chunksize)
 {
-  if (use_sound) {
-    return Mix_OpenAudio( frequency, format, channels, chunksize );
-  }
-  else {
-    // let the user think that the audio device was correctly opened
-    // and keep the compiler happy :-D
-    return 0;
-  }
+  return Mix_OpenAudio( frequency, format, channels, chunksize );
 }
 
 
@@ -54,9 +47,10 @@ Mix_Chunk * load_sound(char * file)
 
   snd = Mix_LoadWAV(file);
 
-  if (snd == NULL)
+  /* printf message and abort if there is an initialized audio device */
+  if ((snd == NULL) && (audio_device == YES))
     st_abort("Can't load", file);
-   
+
   return(snd);
 }
 
@@ -69,76 +63,87 @@ Mix_Music * load_song(char * file)
 
   sng = Mix_LoadMUS(file);
 
-  if (sng == NULL)
+  /* printf message and abort if there is an initialized audio device */
+  if ((sng == NULL) && (audio_device == YES))
     st_abort("Can't load", file);
-  
   return (sng);
 }
 
 
 /* --- PLAY A SOUND --- */
 
- void play_sound(Mix_Chunk * snd)
- {
-  /* this won't call the function if the user has disabled sound */
-  if (use_sound) {
-    Mix_PlayChannel(-1, snd, 0);
-  }
+void play_sound(Mix_Chunk * snd)
+{
+  /* this won't call the function if the user has disabled sound
+   * either via menu or via command-line option
+   */
+  if ((use_sound == YES) && (audio_device == YES))
+    {
+      Mix_PlayChannel(-1, snd, 0);
+    }
 }
 
 
 void free_chunk(Mix_Chunk *chunk)
 {
-  if (chunk != NULL) {
-   DEBUG_MSG( __PRETTY_FUNCTION__ );
-   Mix_FreeChunk( chunk );
-   chunk = NULL;
-  }
+  if (chunk != NULL)
+    {
+      DEBUG_MSG( __PRETTY_FUNCTION__ );
+      Mix_FreeChunk( chunk );
+      chunk = NULL;
+    }
 }
 
 int playing_music(void)
 {
-  if (use_sound) {
-    return Mix_PlayingMusic();
-  }
-  else {
-    /* we are in --disable-sound we can't be playing music */
-    return 0;
-  }
+  if (use_sound)
+    {
+      return Mix_PlayingMusic();
+    }
+  else
+    {
+      /* we are in --disable-sound we can't be playing music */
+      return 0;
+    }
 }
 
 
 int halt_music(void)
 {
-  if (use_sound) {
-    return Mix_HaltMusic();
-  }
-  else {
-    return 0;
-  }
+  if ((use_sound == YES) && (audio_device == YES))
+    {
+      return Mix_HaltMusic();
+    }
+  else
+    {
+      return 0;
+    }
 }
 
 
 int play_music(Mix_Music *music, int loops)
 {
-  if (use_sound) {
-    DEBUG_MSG(__PRETTY_FUNCTION__);
-    return Mix_PlayMusic(music, loops);
-  }
-  else {
-    /* return error since you're trying to play music in --disable-sound mode */
-    return -1;
-  }
+  if ((use_sound == YES) && (audio_device == YES))
+    {
+      DEBUG_MSG(__PRETTY_FUNCTION__);
+      return Mix_PlayMusic(music, loops);
+    }
+  else
+    {
+      /* return error since you're trying to play music in --disable-sound mode */
+      return -1;
+    }
 }
 
 
 void free_music(Mix_Music *music)
 {
-  if ( music != NULL ) {
-    DEBUG_MSG(__PRETTY_FUNCTION__);
-    Mix_FreeMusic( music );
-    music = NULL;
-  }
+  if ( music != NULL )
+    {
+      DEBUG_MSG(__PRETTY_FUNCTION__);
+      Mix_FreeMusic( music );
+      music = NULL;
+    }
 }
 
 #else
@@ -148,14 +153,30 @@ int open_audio (int frequency, int format, int channels, int chunksize)
   return -1;
 }
 
-void* load_sound(void* file) { return NULL; }
-void play_sound(void * snd) {}
-void* load_song(void* file) { return NULL; }
+void* load_sound(void* file)
+{
+  return NULL;
+}
+void play_sound(void * snd)
+{}
+void* load_song(void* file)
+{
+  return NULL;
+}
 
-int playing_music() { return 0; }
-void halt_music() {}
-int play_music(void *music, int loops) { return 0;}
-void free_music(void *music) {}
-void free_chunk(void *chunk) {}
+int playing_music()
+{
+  return 0;
+}
+void halt_music()
+{}
+int play_music(void *music, int loops)
+{
+  return 0;
+}
+void free_music(void *music)
+{}
+void free_chunk(void *chunk)
+{}
 
 #endif
index 3bab45b..aeeb0fd 100644 (file)
@@ -6,25 +6,28 @@
   by Bill Kendrick
   bill@newbreedsoftware.com
   http://www.newbreedsoftware.com/supertux/
-
   April 22, 2000 - July 15, 2002
 */
 
 #ifndef SUPERTUX_SOUND_H
 #define SUPERTUX_SOUND_H
 
- /*all the sounds we have*/
+#include "defines.h"     /* get YES/NO defines */
+
+/*all the sounds we have*/
 #define NUM_SOUNDS 16
 
 /*global variable*/
 int use_sound;
+int audio_device;        /* != 0: available and initialized */
 
 /* enum of different internal music types */
 enum Music_Type {
-        NO_MUSIC,
-        LEVEL_MUSIC,
-        HURRYUP_MUSIC,
-        HERRING_MUSIC
+  NO_MUSIC,
+  LEVEL_MUSIC,
+  HURRYUP_MUSIC,
+  HERRING_MUSIC
 } current_music;
 
 
@@ -65,7 +68,8 @@ void* load_song(void* file);
 int playing_music();
 void halt_music();
 int play_music(void *music, int loops);
-void free_music(void *music);;
+void free_music(void *music);
+;
 void free_chunk(void *chunk);
 
 #endif