enemy.h -> badguy.h
[supertux.git] / src / gameloop.c
index ff8c6ca..f8ed6e5 100644 (file)
@@ -31,7 +31,9 @@
 #include "setup.h"
 #include "high_scores.h"
 #include "menu.h"
-
+#include "badguy.h"
+#include "world.h"
+#include "player.h"
 
 /* Sound files: */
 
@@ -105,7 +107,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 +135,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,6 +179,10 @@ void game_event(void)
 
           key = event.key.keysym.sym;
 
+          /* Check for menu-events, if the menu is shown */
+          if(show_menu)
+            menu_event(key);
+
           if (key == SDLK_ESCAPE)
             {
               /* Escape: Open/Close the menu: */
@@ -214,10 +221,6 @@ void game_event(void)
 
           key = event.key.keysym.sym;
 
-          /* Check for menu-events, if the menu is shown */
-          if(show_menu)
-            menu_event(key);
-
           if (key == SDLK_RIGHT)
             {
               right = UP;
@@ -248,15 +251,15 @@ void game_event(void)
                     game_pause = 1;
                 }
             }
-          else if (key == SDLK_TAB)
+          else if (key == SDLK_TAB && debug_mode == YES)
             {
               tux_size = !tux_size;
             }
-          else if (key == SDLK_END)
+          else if (key == SDLK_END && debug_mode == YES)
             {
               distros += 50;
             }
-          else if (key == SDLK_SPACE)
+          else if (key == SDLK_SPACE && debug_mode == YES)
             {
               next_level = 1;
             }
@@ -555,9 +558,9 @@ int game_action(void)
               if (score > highscore)
                 save_hs(score);
 
-             unloadlevelgfx();
+              unloadlevelgfx();
               unloadlevelsong();
-              unloadshared();        
+              unloadshared();
               return(0);
             } /* if (lives < 0) */
         }
@@ -578,10 +581,18 @@ int game_action(void)
 
 
   /* Keep tux in bounds: */
-
   if (tux_x < 0)
     tux_x = 0;
-  else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
+    else if (tux_x < 160 && scroll_x > 0 && debug_mode == YES)
+    {
+    scroll_x = scroll_x - ( 160 - tux_x);
+    tux_x = 160;
+    
+    if(scroll_x < 0)
+     scroll_x = 0;
+   
+    }
+    else if (tux_x > 320 && scroll_x < ((level_width * 32) - 640))
     {
       /* Scroll the screen in past center: */
 
@@ -2150,6 +2161,13 @@ 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);
+    }
+    
   if(game_pause)
     drawcenteredtext("PAUSE",230,letters_red, NO_UPDATE);
 
@@ -2256,7 +2274,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: */
@@ -2874,6 +2892,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: */
 
@@ -2890,10 +2912,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]);
 
@@ -3655,4 +3680,5 @@ void drawresultscreen(void)
   sleep(2);
 }
 
-
+void savegame(void)
+{}