applied a patch by Duong-Khang NGUYEN <neoneurone@users.sf.net> and fixed it. ;)...
authorTobias Gläßer <tobi.web@gmx.de>
Fri, 26 Dec 2003 22:01:15 +0000 (22:01 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Fri, 26 Dec 2003 22:01:15 +0000 (22:01 +0000)
SVN-Revision: 47

src/enemy.h [new file with mode: 0644]
src/gameloop.c
src/gameloop.h
src/menu.c
src/menu.h
src/player.h [new file with mode: 0644]
src/setup.c
src/sound.c
src/sound.h
src/title.c
src/world.h [new file with mode: 0644]

diff --git a/src/enemy.h b/src/enemy.h
new file mode 100644 (file)
index 0000000..58b2b0c
--- /dev/null
@@ -0,0 +1,33 @@
+//
+// C++ Interface: enemy
+//
+// Description:
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de> (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+
+/* Types: */
+
+
+
+typedef struct bad_guy_type
+  {
+    int alive;
+    int mode;
+    int dying;
+    int timer;
+    int kind;
+    int seen;
+    int dir;
+    int x;
+    int y;
+    int xm;
+    int ym;
+    unsigned int time_updated;
+  }
+bad_guy_type;
index 86ae816..2561d03 100644 (file)
@@ -31,7 +31,9 @@
 #include "setup.h"
 #include "high_scores.h"
 #include "menu.h"
-
+#include "enemy.h"
+#include "world.h"
+#include "player.h"
 
 /* Sound files: */
 
@@ -2157,8 +2159,7 @@ void game_draw()
     {
       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);
 
@@ -2265,7 +2266,7 @@ int gameloop(void)
 
       now_time = SDL_GetTicks();
       if (now_time < last_time + FPS)
-        SDL_Delay(last_time + FPS - now_time);
+       SDL_Delay(last_time + FPS - now_time);
 
 
       /* Handle time: */
@@ -2903,10 +2904,13 @@ void loadshared(void)
 
   /* Sound effects: */
 
-  /*  if (use_sound) // this can help speeding up a little, but
-     we shouldn't take care about "use_sound" here, it's load_sound's job
-     / Send a mail to neoneurone@users.sf.net, if you have another opinion. :)
-     */
+  /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
+                    // initialize sounds[i] with the correct pointer's value:
+                    // NULL or something else. And it will be dangerous to
+                    // play with not-initialized pointers.
+                    // This is also true with if (use_music)
+     Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
+  */
   for (i = 0; i < NUM_SOUNDS; i++)
     sounds[i] = load_sound(soundfilenames[i]);
 
index f5d0e13..9b226b7 100644 (file)
@@ -133,37 +133,6 @@ enum {
 #define SCORE_DISTRO 25
 
 
-/* Types: */
-
-typedef struct bouncy_distro_type {
-  int alive, x, y, ym;
-} bouncy_distro_type;
-
-typedef struct broken_brick_type {
-  int alive, x, y, xm, ym;
-} broken_brick_type;
-
-typedef struct bouncy_brick_type {
-  int alive, x, y, offset, offset_m, shape;
-} bouncy_brick_type;
-
-typedef struct bad_guy_type {
-  int alive, mode, dying, timer, kind, seen, dir, x, y, xm, ym;
-} bad_guy_type;
-
-typedef struct floating_score_type {
-  int alive, timer, x, y, value;
-} floating_score_type;
-
-typedef struct upgrade_type {
-  int alive, kind, height, x, y, xm, ym;
-} upgrade_type;
-
-typedef struct bullet_type {
-  int alive, x, y, xm, ym;
-} bullet_type;
-
-
 /* Function prototypes: */
 
 int gameloop(void);
index 03401fa..7f0711a 100644 (file)
@@ -34,6 +34,104 @@ void initmenu(void)
   menuaction = -1;
 }
 
+/* ---- Menu Options - Item Sound On/off ----*/
+void menu_option_sound()
+{
+  if (audio_device == YES) {
+    if(menuitem == 1) {
+       if(use_sound == YES) {
+         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(use_sound == YES) {
+           use_sound = NO;
+         }
+         else {
+           use_sound = YES;
+         }
+         menu_change = YES;
+       }
+    }
+    else {
+      if(use_sound == YES)
+        drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
+      else
+        drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
+    }
+  }
+  else { /* if audio_device != YES */
+    /* 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_black, NO_UPDATE);
+    }
+  }
+}
+
+
+/* ---- Menu Options - Item Music On/off ----*/
+void menu_option_music()
+{
+  if (audio_device == YES) {
+    if(menuitem == 2) {
+      if(use_music == YES) {
+        drawcenteredtext("Music ON", 256, letters_red, NO_UPDATE);
+      }
+     else {
+        drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE);
+      }
+      if(menuaction == MN_HIT) { /* Disable/Enable music */
+        if(use_music == YES) {  /* In the menu no music is played, so we have to check only use_music */
+            if(playing_music()) 
+              halt_music();
+             use_music = NO;
+        }
+        else {
+          use_music = YES;
+          if (!playing_music()) {
+            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;
+      }
+    } /* if menuitem != 2 : print normal blue font */
+    else {
+      if(use_music == YES) {
+        drawcenteredtext("Music ON", 256, letters_blue, NO_UPDATE);
+      }
+      else {
+        drawcenteredtext("Music OFF", 256, letters_blue, NO_UPDATE);
+      }
+    }
+  }
+  else { /* if audio_device != YES */
+   /* let the user move over the deactivated option */
+    if (menuitem == 2) {
+      drawcenteredtext("Music OFF", 256, letters_red, NO_UPDATE);
+    }
+    else {
+      drawcenteredtext("Music OFF", 256, letters_black, NO_UPDATE);
+    }
+  }
+}
+
 /* --- MENU --- */
 /* Draw the menu and execute the (menu)events */
 int drawmenu(void)
@@ -56,8 +154,8 @@ int drawmenu(void)
   if(menumenu == MENU_MAIN)
     {
       /* Does the menu item exist? If not, we reset to the most down item */
-      if(menuitem > 2)
-        menuitem = 2;
+      if(menuitem >= MENU_MAIN_ITEM_MAX)
+        menuitem = MENU_MAIN_ITEM_MAX - 1;
 
       /*The menu looks different, when the game is started */
       if(game_started)
@@ -120,8 +218,8 @@ int drawmenu(void)
     }
   else if(menumenu == MENU_OPTIONS)
     {
-      if(menuitem > 2)
-        menuitem = 2;
+      if(menuitem >= MENU_OPTIONS_ITEM_MAX )
+        menuitem = MENU_OPTIONS_ITEM_MAX - 1;
 
       if(menuitem == 0)
         {
@@ -147,66 +245,15 @@ int drawmenu(void)
             drawcenteredtext("Fullscreen OFF", 192, letters_blue, NO_UPDATE);
         }
 
-      if (audio_device == YES)
-        {
-          if(menuitem == 1)
-            {
-              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(use_sound)
-                    {
-                      if(playing_music())
-                        halt_music();
-                      use_sound = 0;
-                    }
-                  else
-                    {
-                      use_sound = 1;
-                      if (playing_music())
-                        {
-                          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;
-                }
-            }
-          else
-            {
-              if(use_sound)
-                drawcenteredtext("Sound ON", 224, letters_blue, NO_UPDATE);
-              else
-                drawcenteredtext("Sound OFF", 224, letters_blue, NO_UPDATE);
-            }
-        }
-      else  /* if audio_device != YES */
-        {
-          /* 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_black, NO_UPDATE);
-        }
+      /* handle menu sound on/off option */
+      menu_option_sound();     
 
-      if(menuitem == 2)
+      /* handle menu music on/off option */
+      menu_option_music();
+   
+      if(menuitem == 3)
         {
-          drawcenteredtext("Back", 256, letters_red, NO_UPDATE);
+          drawcenteredtext("Back", 288, letters_red, NO_UPDATE);
           if(menuaction == MN_HIT) /* Go back to main menu. */
             {
               menumenu = MENU_MAIN;
@@ -214,7 +261,7 @@ int drawmenu(void)
             }
         }
       else
-        drawcenteredtext("Back", 256, letters_blue, NO_UPDATE);
+        drawcenteredtext("Back", 288, letters_blue, NO_UPDATE);
 
     }
 
index bc6da3a..90a162d 100644 (file)
@@ -22,6 +22,9 @@ int menumenu;
 int show_menu;
 int menu_change;
 
+#define MENU_MAIN_ITEM_MAX 3
+#define MENU_OPTIONS_ITEM_MAX 4
+
 /* Action done on the menu */
 enum {
   MN_UP,
diff --git a/src/player.h b/src/player.h
new file mode 100644 (file)
index 0000000..1c9420e
--- /dev/null
@@ -0,0 +1,34 @@
+//
+// C++ Interface: tux
+//
+// Description: 
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+typedef struct upgrade_type
+  {
+    int alive;
+    int kind;
+    int height;
+    int x;
+    int y;
+    int xm;
+    int ym;
+  }
+upgrade_type;
+
+typedef struct bullet_type
+  {
+    int alive;
+    int x;
+    int y;
+    int xm;
+    int ym;
+  }
+bullet_type;
+
index 0dfeb7e..d7626d5 100644 (file)
@@ -42,7 +42,7 @@ void usage(char * prog, int ret);
 void st_setup(void)
 {
 
-  /* Set SuperTux configuration and save directories
+  /* Set SuperTux configuration and save directories */
 
   /* Get home directory (from $HOME variable)... if we can't determine it,
      use the current directory ("."): */
@@ -60,7 +60,7 @@ void st_setup(void)
   st_save_dir = (char *) malloc(sizeof(char) * (strlen(st_dir) + strlen("/save") + 1));
 
   strcpy(st_save_dir,st_dir);
-  strcpy(st_save_dir,"/save");
+  strcat(st_save_dir,"/save");
 
   /* Create them. In the case they exist it won't destroy anything. */
   mkdir(st_dir, 0755);
@@ -154,15 +154,22 @@ void st_setup(void)
     {
       if (SDL_Init(SDL_INIT_AUDIO) < 0)
         {
-          /* only print out message if sound was not disabled at command-line */
-          if (use_sound == YES)
+          /* only print out message if sound or music
+             was not disabled at command-line
+           */
+          if (use_sound == YES || use_music == 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;
             }
+          /* keep the programming logic the same :-)
+             because in this case, use_sound & use_music' values are ignored
+             when there's no available audio device
+          */
+          use_sound = NO;
+          use_music = NO;
           audio_device = NO;
         }
     }
@@ -174,16 +181,19 @@ void st_setup(void)
     {
       if (open_audio(44100, AUDIO_S16, 2, 512) < 0)
         {
-          /* only print out message if sound was not disabled at command-line */
-          if (use_sound == YES)
+          /* only print out message if sound or music
+             was not disabled at command-line
+           */
+          if ((use_sound == YES) || (use_music == 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;
             }
+          use_sound = NO;
+          use_music = NO;
           audio_device = NO;
         }
     }
@@ -193,7 +203,7 @@ void st_setup(void)
 
   if (use_fullscreen == YES)
     {
-      screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN) ; /* | SDL_HWSURFACE); */
+      screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
       if (screen == NULL)
         {
           fprintf(stderr,
@@ -318,10 +328,12 @@ void parseargs(int argc, char * argv[])
 #ifndef NOSOUND
 
   use_sound = YES;
+  use_music = YES;
   audio_device = YES;
 #else
 
   use_sound = NO;
+  use_music = NO;
   audio_device = NO;
 #endif
 
@@ -351,13 +363,24 @@ void parseargs(int argc, char * argv[])
         }
       else if (strcmp(argv[i], "--disable-sound") == 0)
         {
-          /* Disable the compiled in sound & music feature */
+          /* Disable the compiled in sound feature */
 #ifndef NOSOUND
-          printf("Sounds and music disabled \n");
+          printf("Sounds disabled \n");
           use_sound = NO;
 #else
 
-          printf("Sounds and music feature is not compiled in \n");
+          printf("Warning: Sounds feature is not compiled in \n");
+          printf("Warning: Sounds feature is not compiled in \n");
+#endif
+        }
+      else if (strcmp(argv[i], "--disable-music") == 0)
+        {
+          /* Disable the compiled in sound feature */
+#ifndef NOSOUND
+          printf("Music disabled \n");
+          use_music = NO;
+#else
+          printf("Warning: Music feature is not compiled in \n");
 #endif
 
         }
@@ -368,7 +391,9 @@ void parseargs(int argc, char * argv[])
 
           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("  --disable-sound     - If sound support was compiled in,  this will\n                        disable sound for this session of the game.\n\n");
+
+          printf("  --disable-music     - Like above, but this will disable music.\n\n");
 
           printf("  --fullscreen        - Run in fullscreen mode.\n\n");
 
@@ -417,8 +442,8 @@ void usage(char * prog, int ret)
 
   /* Display the usage message: */
 
-  fprintf(fi, "Usage: %s [--fullscreen] | [--disable-sound] |  [--usage | --help | --version]\n",
-          prog);
+  fprintf(fi, "Usage: %s [--fullscreen] [--disable-sound] [--disable-music] | [--usage | --help | --version]\n",
+           prog);
 
 
   /* Quit! */
index f00143d..cab9566 100644 (file)
   April 22, 2000 - July 15, 2002
 */
 
-#include <stdio.h>
+/*
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
-#include <SDL.h>
-#include <SDL_image.h>
+*/
 
 #ifdef LINUX
 #include <pwd.h>
@@ -96,13 +95,13 @@ void free_chunk(Mix_Chunk *chunk)
 
 int playing_music(void)
 {
-  if (use_sound)
+  if (use_music == YES)
     {
       return Mix_PlayingMusic();
     }
   else
     {
-      /* we are in --disable-sound we can't be playing music */
+      /* we are in --disable-music we can't be playing music */
       return 0;
     }
 }
@@ -110,7 +109,7 @@ int playing_music(void)
 
 int halt_music(void)
 {
-  if ((use_sound == YES) && (audio_device == YES))
+  if ((use_music == YES) && (audio_device == YES))
     {
       return Mix_HaltMusic();
     }
@@ -123,7 +122,7 @@ int halt_music(void)
 
 int play_music(Mix_Music *music, int loops)
 {
-  if ((use_sound == YES) && (audio_device == YES))
+  if ((use_music == YES) && (audio_device == YES))
     {
       DEBUG_MSG(__PRETTY_FUNCTION__);
       return Mix_PlayMusic(music, loops);
index aeeb0fd..6e57880 100644 (file)
@@ -8,6 +8,9 @@
   http://www.newbreedsoftware.com/supertux/
  
   April 22, 2000 - July 15, 2002
+
+  Current maintainer:
+        Duong-Khang NGUYEN <neoneurone@users.sf.net>
 */
 
 #ifndef SUPERTUX_SOUND_H
@@ -20,6 +23,7 @@
 
 /*global variable*/
 int use_sound;
+int use_music;
 int audio_device;        /* != 0: available and initialized */
 
 /* enum of different internal music types */
index 3525127..993095c 100644 (file)
@@ -39,7 +39,7 @@ int title(void)
   SDL_Surface * title, * anim1, * anim2;
   SDL_Event event;
   SDLKey key;
-  int done, quit, frame, pict;
+  int done, quit, frame, pict, last_highscore;
   char str[80];
 
   game_started = 0;
@@ -73,7 +73,8 @@ int title(void)
 
 
   /* Draw the high score: */
-  sprintf(str, "High score: %d", load_hs());
+  last_highscore = load_hs();
+  sprintf(str, "High score: %d", last_highscore);
   drawcenteredtext(str, 460, letters_red, UPDATE);
 
   while (!done && !quit)
@@ -133,7 +134,7 @@ int title(void)
           drawimage(title, 0, 0, UPDATE);
 
           /* Draw the high score: */
-          sprintf(str, "High score: %d", load_hs());
+          sprintf(str, "High score: %d", last_highscore);
           drawcenteredtext(str, 460, letters_red, UPDATE);
         }
 
diff --git a/src/world.h b/src/world.h
new file mode 100644 (file)
index 0000000..24385f7
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// C++ Interface: world
+//
+// Description: 
+//
+//
+// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+typedef struct bouncy_distro_type /*It is easier to read the sources IMHO, if we don't write something like int a,b,c; */
+  {
+    int alive;
+    int x;
+    int y;
+    int ym;
+  }
+bouncy_distro_type;
+
+typedef struct broken_brick_type
+  {
+    int alive;
+    int x;
+    int y;
+    int xm;
+    int ym;
+  }
+broken_brick_type;
+
+typedef struct bouncy_brick_type
+  {
+    int alive;
+    int x;
+    int y;
+    int offset;
+    int offset_m;
+    int shape;
+  }
+bouncy_brick_type;
+
+typedef struct floating_score_type
+  {
+    int alive;
+    int timer;
+    int x;
+    int y;
+    int value;
+  }
+floating_score_type;
+