fixed a few bugs. (One of them thanks to a patch from Ricardo). Made more code cleanu...
authorTobias Gläßer <tobi.web@gmx.de>
Sun, 25 Jan 2004 02:29:25 +0000 (02:29 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Sun, 25 Jan 2004 02:29:25 +0000 (02:29 +0000)
SVN-Revision: 102

src/defines.h
src/gameloop.c
src/globals.h
src/leveleditor.c
src/player.c
src/player.h
src/screen.c
src/screen.h
src/setup.c
src/special.c
src/type.c

index b23e03c..b2d16f1 100644 (file)
 
 #define MAX_WALK_XM 2.3
 #define MAX_RUN_XM 3.2
-#define MAX_YM 10
+#define MAX_YM 10.0
 #define MAX_JUMP_TIME 1000
-#define MAX_LIVES 4
+#define MAX_LIVES 4.0
 
-#define WALK_SPEED 1
+#define WALK_SPEED 1.0
 #define RUN_SPEED 1.5
 #define JUMP_SPEED 1.5
 
-#define GRAVITY 1
-#define YM_FOR_JUMP 50
-#define KILL_BOUNCE_YM 8
+#define GRAVITY 1.0
+#define YM_FOR_JUMP 50.0
+#define KILL_BOUNCE_YM 8.0
 
-#define SKID_XM 2
-#define SKID_TIME 4
+#define SKID_XM 2.0
+#define SKID_TIME 200
 
 /* Size constraints: */
 
index 5bdd201..558e2d6 100644 (file)
@@ -52,6 +52,7 @@ SDLKey key;
 char level_subset[100];
 char str[60];
 timer_type time_left;
+float fps_fps;
 
 /* Local function prototypes: */
 
@@ -94,7 +95,7 @@ void start_timers(void)
 void activate_bad_guys(void)
 {
   int x,y;
-  
+
   /* Activate bad guys: */
 
   for (y = 0; y < 15; y++)
@@ -103,7 +104,7 @@ void activate_bad_guys(void)
         {
           if (current_level.tiles[y][x] >= '0' && current_level.tiles[y][x] <= '9')
             {
-             add_bad_guy(x * 32, y * 32, current_level.tiles[y][x] - '0');
+              add_bad_guy(x * 32, y * 32, current_level.tiles[y][x] - '0');
               current_level.tiles[y][x] = '.';
             }
         }
@@ -117,18 +118,21 @@ void game_event(void)
 {
   while (SDL_PollEvent(&event))
     {
-    switch(event.type)
-      {
-      case SDL_QUIT:        /* Quit event - quit: */
+      switch(event.type)
+        {
+        case SDL_QUIT:        /* Quit event - quit: */
           quit = 1;
           break;
-      case SDL_KEYDOWN:     /* A keypress! */
+        case SDL_KEYDOWN:     /* A keypress! */
           key = event.key.keysym.sym;
 
           /* Check for menu-events, if the menu is shown */
           if(show_menu)
             menu_event(key);
 
+         if(player_keydown_event(&tux,key))
+         break;
+           
           switch(key)
             {
             case SDLK_ESCAPE:    /* Escape: Open/Close the menu: */
@@ -139,47 +143,20 @@ void game_event(void)
                   else
                     show_menu = 1;
                 }
-               break;
-          case SDLK_RIGHT:
-              tux.input.right = DOWN;
-               break;
-          case SDLK_LEFT:
-              tux.input.left = DOWN;
-            break;
-          case SDLK_UP:
-              tux.input.up = DOWN;
-            break;
-          case SDLK_DOWN:
-              tux.input.down = DOWN;
-            break;
-          case SDLK_LCTRL:
-              tux.input.fire = DOWN;
-            break;
-           default:
-            break;
-        }
-        break;
-      case SDL_KEYUP:      /* A keyrelease! */
+              break;
+            default:
+              break;
+            }
+          break;
+        case SDL_KEYUP:      /* A keyrelease! */
           key = event.key.keysym.sym;
-
+         
+         if(player_keyup_event(&tux,key))
+         break;          
+         
           switch(key)
-           {
-          case SDLK_RIGHT:
-              tux.input.right = UP;
-            break;
-          case SDLK_LEFT:
-              tux.input.left = UP;
-            break;
-          case SDLK_UP:
-              tux.input.up = UP;
-            break;
-          case SDLK_DOWN:
-              tux.input.down = UP;
-            break;
-          case SDLK_LCTRL:
-              tux.input.fire = UP;
-            break;
-          case SDLK_p:
+            {
+            case SDLK_p:
               if(!show_menu)
                 {
                   if(game_pause)
@@ -187,37 +164,38 @@ void game_event(void)
                   else
                     game_pause = 1;
                 }
-            break;
-          case SDLK_TAB:
-            if(debug_mode == YES)
-              tux.size = !tux.size;
-            break;
-          case SDLK_END:
-            if(debug_mode == YES)
-              distros += 50;
-            break;
-          case SDLK_SPACE:
-            if(debug_mode == YES)
-              next_level = 1;
-            break;
-          case SDLK_DELETE:
-            if(debug_mode == YES)
-              tux.got_coffee = 1;
-            break;
-          case SDLK_INSERT:
-            if(debug_mode == YES)
-              timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
-            break;
-           default:
-            break;
-        }
-        break;
+              break;
+            case SDLK_TAB:
+              if(debug_mode == YES)
+                tux.size = !tux.size;
+              break;
+            case SDLK_END:
+              if(debug_mode == YES)
+                distros += 50;
+              break;
+            case SDLK_SPACE:
+              if(debug_mode == YES)
+                next_level = 1;
+              break;
+            case SDLK_DELETE:
+              if(debug_mode == YES)
+                tux.got_coffee = 1;
+              break;
+            case SDLK_INSERT:
+              if(debug_mode == YES)
+                timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
+              break;
+            default:
+              break;
+            }
+          break;
 #ifdef JOY_YES
-      case SDL_JOYAXISMOTION:
-        switch(event.jaxis.axis)
-           {
-           case JOY_X:
-             printf("X: %d\n", event.jaxis.value);
+
+        case SDL_JOYAXISMOTION:
+          switch(event.jaxis.axis)
+            {
+            case JOY_X:
+              printf("X: %d\n", event.jaxis.value);
               if (event.jaxis.value < -1024)
                 tux.input.left = DOWN;
               else if (event.jaxis.value > 1024)
@@ -227,8 +205,8 @@ void game_event(void)
                 tux.input.right = DOWN;
               else if (event.jaxis.value < -1024)
                 tux.input.right = UP;
-            break;
-          case JOY_Y:
+              break;
+            case JOY_Y:
               if (event.jaxis.value > 1024)
                 tux.input.down = DOWN;
               else if (event.jaxis.value < -1024)
@@ -242,18 +220,18 @@ void game_event(void)
                   else
                     menuaction = MN_UP;
                 }
-            break;
+              break;
             default:
               break;
-        }
-        break;
-      case SDL_JOYBUTTONDOWN:
+            }
+          break;
+        case SDL_JOYBUTTONDOWN:
           if (event.jbutton.button == JOY_A)
             tux.input.up = DOWN;
           else if (event.jbutton.button == JOY_B)
             tux.input.fire = DOWN;
-        break;
-      case SDL_JOYBUTTONUP:
+          break;
+        case SDL_JOYBUTTONUP:
           if (event.jbutton.button == JOY_A)
             tux.input.up = UP;
           else if (event.jbutton.button == JOY_B)
@@ -262,8 +240,8 @@ void game_event(void)
           if(show_menu)
             menuaction = MN_HIT;
           break;
-       default:
-         break;
+        default:
+          break;
 
         }
 #endif
@@ -276,7 +254,7 @@ void game_event(void)
 
 int game_action(void)
 {
-int i;
+  int i;
 
   /* (tux_dying || next_level) */
   if (tux.dying || next_level)
@@ -294,12 +272,13 @@ int i;
           level++;
           next_level = 0;
           drawresultscreen();
+         player_level_begin(&tux);
         }
       else
         {
 
-       player_dying(&tux);
-       
+          player_dying(&tux);
+
           /* No more lives!? */
 
           if (tux.lives < 0)
@@ -311,7 +290,7 @@ int i;
               unloadlevelgfx();
               unloadlevelsong();
               unloadshared();
-             arrays_free();
+              arrays_free();
               return(0);
             } /* if (lives < 0) */
         }
@@ -388,7 +367,7 @@ int i;
 
   for (i = 0; i < num_upgrades; i++)
     {
-       upgrade_action(&upgrades[i]);
+      upgrade_action(&upgrades[i]);
     }
 
 
@@ -396,7 +375,7 @@ int i;
 
   for (i = 0; i < num_bad_guys; i++)
     {
-       badguy_action(&bad_guys[i]);
+      badguy_action(&bad_guys[i]);
     }
 
   /* Handle all possible collisions. */
@@ -420,14 +399,14 @@ void game_draw()
       if (timer_check(&super_bkgd_timer))
         texture_draw(&img_super_bkgd, 0, 0, NO_UPDATE);
       else
-       clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue);
+        clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue);
     }
 
   /* Draw background: */
 
-  for (y = 0; y < 15; y++)
+  for (y = 0; y < 15; ++y)
     {
-      for (x = 0; x < 21; x++)
+      for (x = 0; x < 21; ++x)
         {
           drawshape(x * 32 - ((int)scroll_x % 32), y * 32,
                     current_level.tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
@@ -437,49 +416,49 @@ void game_draw()
 
   /* (Bouncy bricks): */
 
-  for (i = 0; i < num_bouncy_bricks; i++)
+  for (i = 0; i < num_bouncy_bricks; ++i)
     {
-       bouncy_brick_draw(&bouncy_bricks[i]);
+      bouncy_brick_draw(&bouncy_bricks[i]);
     }
 
 
   /* (Bad guys): */
 
-  for (i = 0; i < num_bad_guys; i++)
+  for (i = 0; i < num_bad_guys; ++i)
     {
-       badguy_draw(&bad_guys[i]);
+      badguy_draw(&bad_guys[i]);
     }
 
   /* (Tux): */
-  
+
   player_draw(&tux);
 
   /* (Bullets): */
 
-  for (i = 0; i < num_bullets; i++)
+  for (i = 0; i < num_bullets; ++i)
     {
-       bullet_draw(&bullets[i]);
+      bullet_draw(&bullets[i]);
     }
 
   /* (Floating scores): */
 
-  for (i = 0; i < num_floating_scores; i++)
+  for (i = 0; i < num_floating_scores; ++i)
     {
-       floating_score_draw(&floating_scores[i]);
+      floating_score_draw(&floating_scores[i]);
     }
 
 
   /* (Upgrades): */
 
-  for (i = 0; i < num_upgrades; i++)
+  for (i = 0; i < num_upgrades; ++i)
     {
-       upgrade_draw(&upgrades[i]);
+      upgrade_draw(&upgrades[i]);
     }
 
 
   /* (Bouncy distros): */
 
-  for (i = 0; i < num_bouncy_distros; i++)
+  for (i = 0; i < num_bouncy_distros; ++i)
     {
       bouncy_distro_draw(&bouncy_distros[i]);
     }
@@ -487,9 +466,9 @@ void game_draw()
 
   /* (Broken bricks): */
 
-  for (i = 0; i < num_broken_bricks; i++)
+  for (i = 0; i < num_broken_bricks; ++i)
     {
-       broken_brick_draw(&broken_bricks[i]);
+      broken_brick_draw(&broken_bricks[i]);
     }
 
   drawstatus();
@@ -513,7 +492,9 @@ void game_draw()
 int gameloop(void)
 {
 
-  Uint32 last_time, now_time;
+  /*Uint32 last_time, now_time*/
+  int fps_cnt;
+  timer_type fps_timer, frame_timer;
 
   /* Clear screen: */
 
@@ -523,13 +504,13 @@ int gameloop(void)
 
   /* Init the game: */
   arrays_init();
-  
+
   initmenu();
   menumenu = MENU_GAME;
   initgame();
   loadshared();
   set_defaults();
-  
+
   loadlevel(&current_level,"default",level);
   loadlevelgfx(&current_level);
   activate_bad_guys();
@@ -537,22 +518,29 @@ int gameloop(void)
   highscore = load_hs();
 
   player_init(&tux);
-  
+
   levelintro();
   start_timers();
-    
+
   /* --- MAIN GAME LOOP!!! --- */
 
   done = 0;
   quit = 0;
   frame = 0;
   game_pause = 0;
-  
+  timer_init(&fps_timer);
+  timer_init(&frame_timer);
+  fps_cnt = 0;
+
   game_draw();
   do
     {
-      last_time = SDL_GetTicks();
-      frame++;
+      /*last_time = SDL_GetTicks();*/
+      if(!timer_check(&frame_timer))
+      {
+      timer_start(&frame_timer,25);
+      ++frame;
+      }
 
 
       /* Handle events: */
@@ -561,7 +549,7 @@ int gameloop(void)
 
       game_event();
 
-     
+
       /* Handle actions: */
 
       if(!game_pause && !show_menu)
@@ -587,41 +575,56 @@ int gameloop(void)
 
       /* Pause til next frame: */
 
-      now_time = SDL_GetTicks();
-      /*if (now_time < last_time + FPS)
+      /*now_time = SDL_GetTicks();
+      if (now_time < last_time + FPS)
         SDL_Delay(last_time + FPS - now_time);*/
-       SDL_Delay(10);
+       /*printf("%d",timer_get_left(&frame_timer));*/
+      /*SDL_Delay(timer_get_left(&frame_timer) );*/
+       SDL_Delay(10);      
+      
 
 
       /* Handle time: */
 
       if (timer_check(&time_left))
         {
-             /* are we low on time ? */
-      if ((timer_get_left(&time_left) < TIME_WARNING)
-          && (current_music != HURRYUP_MUSIC))
-        {
-          current_music = HURRYUP_MUSIC;
-          /* stop the others music, prepare to play the fast music */
-          if (playing_music())
+          /* are we low on time ? */
+          if ((timer_get_left(&time_left) < TIME_WARNING)
+              && (current_music != HURRYUP_MUSIC))
             {
-              halt_music();
+              current_music = HURRYUP_MUSIC;
+              /* stop the others music, prepare to play the fast music */
+              if (playing_music())
+                {
+                  halt_music();
+                }
             }
-        }
 
         }
-       else
-       player_kill(&tux,KILL);
-       
+      else
+        player_kill(&tux,KILL);
+
 
       /* Keep playing the correct music: */
 
       if (!playing_music())
         {
-          play_current_music();
+          play_current_music();
+        }
+
+      /* Calculate frames per second */
+      if(show_fps)
+        {
+          fps_fps = ((float)1000 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
+          ++fps_cnt;
+
+          if(!timer_check(&fps_timer))
+            {
+              timer_start(&fps_timer,1000);
+              fps_cnt = 0;
+            }
         }
 
-       
     }
   while (!done && !quit);
 
@@ -668,7 +671,7 @@ void loadlevelsong(void)
   level_song = load_song(song_path);
   free(song_path);
 
-  
+
   song_path = (char *) malloc(sizeof(char) * (strlen(DATA_PREFIX) +
                               strlen(current_level.song_title) + 8 + 5));
   song_subtitle = strdup(current_level.song_title);
@@ -690,52 +693,52 @@ void loadshared(void)
 
   texture_load(&tux_right[0],DATA_PREFIX "/images/shared/tux-right-0.png", USE_ALPHA);
   texture_load(&tux_right[1],DATA_PREFIX "/images/shared/tux-right-1.png", USE_ALPHA);
-  texture_load(&tux_right[2],DATA_PREFIX "/images/shared/tux-right-2.png", USE_ALPHA);  
+  texture_load(&tux_right[2],DATA_PREFIX "/images/shared/tux-right-2.png", USE_ALPHA);
 
   texture_load(&tux_left[0],DATA_PREFIX "/images/shared/tux-left-0.png", USE_ALPHA);
   texture_load(&tux_left[1],DATA_PREFIX "/images/shared/tux-left-1.png", USE_ALPHA);
-  texture_load(&tux_left[2],DATA_PREFIX "/images/shared/tux-left-2.png", USE_ALPHA);  
-  
-  texture_load(&firetux_right[0],DATA_PREFIX "/images/shared/firetux-right-0.png", USE_ALPHA);  
-  texture_load(&firetux_right[1],DATA_PREFIX "/images/shared/firetux-right-1.png", USE_ALPHA); 
-  texture_load(&firetux_right[2],DATA_PREFIX "/images/shared/firetux-right-2.png", USE_ALPHA); 
+  texture_load(&tux_left[2],DATA_PREFIX "/images/shared/tux-left-2.png", USE_ALPHA);
 
-  texture_load(&firetux_left[0],DATA_PREFIX "/images/shared/firetux-left-0.png", USE_ALPHA);  
-  texture_load(&firetux_left[1],DATA_PREFIX "/images/shared/firetux-left-1.png", USE_ALPHA); 
-  texture_load(&firetux_left[2],DATA_PREFIX "/images/shared/firetux-left-2.png", USE_ALPHA); 
+  texture_load(&firetux_right[0],DATA_PREFIX "/images/shared/firetux-right-0.png", USE_ALPHA);
+  texture_load(&firetux_right[1],DATA_PREFIX "/images/shared/firetux-right-1.png", USE_ALPHA);
+  texture_load(&firetux_right[2],DATA_PREFIX "/images/shared/firetux-right-2.png", USE_ALPHA);
+
+  texture_load(&firetux_left[0],DATA_PREFIX "/images/shared/firetux-left-0.png", USE_ALPHA);
+  texture_load(&firetux_left[1],DATA_PREFIX "/images/shared/firetux-left-1.png", USE_ALPHA);
+  texture_load(&firetux_left[2],DATA_PREFIX "/images/shared/firetux-left-2.png", USE_ALPHA);
 
 
   texture_load(&cape_right[0] ,DATA_PREFIX "/images/shared/cape-right-0.png",
-                             USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&cape_right[1] ,DATA_PREFIX "/images/shared/cape-right-1.png",
-                             USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&cape_left[0] ,DATA_PREFIX "/images/shared/cape-left-0.png",
-                            USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&cape_left[1] ,DATA_PREFIX "/images/shared/cape-left-1.png",
-                            USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_right[0] ,DATA_PREFIX "/images/shared/bigtux-right-0.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_right[1] ,DATA_PREFIX "/images/shared/bigtux-right-1.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_right[2] ,DATA_PREFIX "/images/shared/bigtux-right-2.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_right_jump ,DATA_PREFIX "/images/shared/bigtux-right-jump.png", USE_ALPHA);
 
   texture_load(&bigtux_left[0] ,DATA_PREFIX "/images/shared/bigtux-left-0.png",
-                              USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_left[1] ,DATA_PREFIX "/images/shared/bigtux-left-1.png",
-                              USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_left[2] ,DATA_PREFIX "/images/shared/bigtux-left-2.png",
-                              USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigtux_left_jump ,DATA_PREFIX "/images/shared/bigtux-left-jump.png", USE_ALPHA);
 
@@ -752,24 +755,24 @@ void loadshared(void)
                USE_ALPHA);
 
   texture_load(&bigfiretux_right[0] ,DATA_PREFIX "/images/shared/bigfiretux-right-0.png",
-                                   USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigfiretux_right[1] ,DATA_PREFIX "/images/shared/bigfiretux-right-1.png",
-                                   USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigfiretux_right[2] ,DATA_PREFIX "/images/shared/bigfiretux-right-2.png",
-                                   USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigfiretux_right_jump ,DATA_PREFIX "/images/shared/bigfiretux-right-jump.png", USE_ALPHA);
 
   texture_load(&bigfiretux_left[0] ,DATA_PREFIX "/images/shared/bigfiretux-left-0.png",
-                                  USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigfiretux_left[1] ,DATA_PREFIX "/images/shared/bigfiretux-left-1.png",
-                                  USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigfiretux_left[2] ,DATA_PREFIX "/images/shared/bigfiretux-left-2.png",
-                                  USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&bigfiretux_left_jump ,DATA_PREFIX "/images/shared/bigfiretux-left-jump.png", USE_ALPHA);
 
@@ -787,44 +790,44 @@ void loadshared(void)
 
 
   texture_load(&ducktux_right ,DATA_PREFIX
-                             "/images/shared/ducktux-right.png",
-                             USE_ALPHA);
+               "/images/shared/ducktux-right.png",
+               USE_ALPHA);
 
   texture_load(&ducktux_left ,DATA_PREFIX
-                            "/images/shared/ducktux-left.png",
-                            USE_ALPHA);
+               "/images/shared/ducktux-left.png",
+               USE_ALPHA);
 
   texture_load(&skidtux_right ,DATA_PREFIX
-                             "/images/shared/skidtux-right.png",
-                             USE_ALPHA);
+               "/images/shared/skidtux-right.png",
+               USE_ALPHA);
 
   texture_load(&skidtux_left ,DATA_PREFIX
-                            "/images/shared/skidtux-left.png",
-                            USE_ALPHA);
+               "/images/shared/skidtux-left.png",
+               USE_ALPHA);
 
   texture_load(&duckfiretux_right ,DATA_PREFIX
-                                 "/images/shared/duckfiretux-right.png",
-                                 USE_ALPHA);
+               "/images/shared/duckfiretux-right.png",
+               USE_ALPHA);
 
   texture_load(&duckfiretux_left ,DATA_PREFIX
-                                "/images/shared/duckfiretux-left.png",
-                                USE_ALPHA);
+               "/images/shared/duckfiretux-left.png",
+               USE_ALPHA);
 
   texture_load(&skidfiretux_right ,DATA_PREFIX
-                                 "/images/shared/skidfiretux-right.png",
-                                 USE_ALPHA);
+               "/images/shared/skidfiretux-right.png",
+               USE_ALPHA);
 
   texture_load(&skidfiretux_left ,DATA_PREFIX
-                                "/images/shared/skidfiretux-left.png",
-                                USE_ALPHA);
+               "/images/shared/skidfiretux-left.png",
+               USE_ALPHA);
 
 
   /* Boxes: */
 
   texture_load(&img_box_full ,DATA_PREFIX "/images/shared/box-full.png",
-                            IGNORE_ALPHA);
+               IGNORE_ALPHA);
   texture_load(&img_box_empty ,DATA_PREFIX "/images/shared/box-empty.png",
-                             IGNORE_ALPHA);
+               IGNORE_ALPHA);
 
 
   /* Water: */
@@ -833,56 +836,56 @@ void loadshared(void)
   texture_load(&img_water ,DATA_PREFIX "/images/shared/water.png", IGNORE_ALPHA);
 
   texture_load(&img_waves[0] ,DATA_PREFIX "/images/shared/waves-0.png",
-                            USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_waves[1] ,DATA_PREFIX "/images/shared/waves-1.png",
-                            USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_waves[2] ,DATA_PREFIX "/images/shared/waves-2.png",
-                            USE_ALPHA);
+               USE_ALPHA);
 
 
   /* Pole: */
 
   texture_load(&img_pole ,DATA_PREFIX "/images/shared/pole.png", USE_ALPHA);
   texture_load(&img_poletop ,DATA_PREFIX "/images/shared/poletop.png",
-                           USE_ALPHA);
+               USE_ALPHA);
 
 
   /* Flag: */
 
   texture_load(&img_flag[0] ,DATA_PREFIX "/images/shared/flag-0.png",
-                           USE_ALPHA);
+               USE_ALPHA);
   texture_load(&img_flag[1] ,DATA_PREFIX "/images/shared/flag-1.png",
-                           USE_ALPHA);
+               USE_ALPHA);
 
 
   /* Cloud: */
 
   texture_load(&img_cloud[0][0] ,DATA_PREFIX "/images/shared/cloud-00.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_cloud[0][1] ,DATA_PREFIX "/images/shared/cloud-01.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_cloud[0][2] ,DATA_PREFIX "/images/shared/cloud-02.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_cloud[0][3] ,DATA_PREFIX "/images/shared/cloud-03.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
 
   texture_load(&img_cloud[1][0] ,DATA_PREFIX "/images/shared/cloud-10.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_cloud[1][1] ,DATA_PREFIX "/images/shared/cloud-11.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_cloud[1][2] ,DATA_PREFIX "/images/shared/cloud-12.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_cloud[1][3] ,DATA_PREFIX "/images/shared/cloud-13.png",
-                               USE_ALPHA);
+               USE_ALPHA);
 
 
   /* Bad guys: */
@@ -890,87 +893,87 @@ void loadshared(void)
   /* (BSOD) */
 
   texture_load(&img_bsod_left[0] ,DATA_PREFIX
-                                "/images/shared/bsod-left-0.png",
-                                USE_ALPHA);
+               "/images/shared/bsod-left-0.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_left[1] ,DATA_PREFIX
-                                "/images/shared/bsod-left-1.png",
-                                USE_ALPHA);
+               "/images/shared/bsod-left-1.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_left[2] ,DATA_PREFIX
-                                "/images/shared/bsod-left-2.png",
-                                USE_ALPHA);
+               "/images/shared/bsod-left-2.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_left[3] ,DATA_PREFIX
-                                "/images/shared/bsod-left-3.png",
-                                USE_ALPHA);
+               "/images/shared/bsod-left-3.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_right[0] ,DATA_PREFIX
-                                 "/images/shared/bsod-right-0.png",
-                                 USE_ALPHA);
+               "/images/shared/bsod-right-0.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_right[1] ,DATA_PREFIX
-                                 "/images/shared/bsod-right-1.png",
-                                 USE_ALPHA);
+               "/images/shared/bsod-right-1.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_right[2] ,DATA_PREFIX
-                                 "/images/shared/bsod-right-2.png",
-                                 USE_ALPHA);
+               "/images/shared/bsod-right-2.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_right[3] ,DATA_PREFIX
-                                 "/images/shared/bsod-right-3.png",
-                                 USE_ALPHA);
+               "/images/shared/bsod-right-3.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_squished_left ,DATA_PREFIX
-                                      "/images/shared/bsod-squished-left.png",
-                                      USE_ALPHA);
+               "/images/shared/bsod-squished-left.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_squished_right ,DATA_PREFIX
-                                       "/images/shared/bsod-squished-right.png",
-                                       USE_ALPHA);
+               "/images/shared/bsod-squished-right.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_falling_left ,DATA_PREFIX
-                                     "/images/shared/bsod-falling-left.png",
-                                     USE_ALPHA);
+               "/images/shared/bsod-falling-left.png",
+               USE_ALPHA);
 
   texture_load(&img_bsod_falling_right ,DATA_PREFIX
-                                      "/images/shared/bsod-falling-right.png",
-                                      USE_ALPHA);
+               "/images/shared/bsod-falling-right.png",
+               USE_ALPHA);
 
 
   /* (Laptop) */
 
   texture_load(&img_laptop_left[0] ,DATA_PREFIX
-                                  "/images/shared/laptop-left-0.png",
-                                  USE_ALPHA);
+               "/images/shared/laptop-left-0.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_left[1] ,DATA_PREFIX
-                                  "/images/shared/laptop-left-1.png",
-                                  USE_ALPHA);
+               "/images/shared/laptop-left-1.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_left[2] ,DATA_PREFIX
-                                  "/images/shared/laptop-left-2.png",
-                                  USE_ALPHA);
+               "/images/shared/laptop-left-2.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_right[0] ,DATA_PREFIX
-                                   "/images/shared/laptop-right-0.png",
-                                   USE_ALPHA);
+               "/images/shared/laptop-right-0.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_right[1] ,DATA_PREFIX
-                                   "/images/shared/laptop-right-1.png",
-                                   USE_ALPHA);
+               "/images/shared/laptop-right-1.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_right[2] ,DATA_PREFIX
-                                   "/images/shared/laptop-right-2.png",
-                                   USE_ALPHA);
+               "/images/shared/laptop-right-2.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_flat_left ,DATA_PREFIX
-                                    "/images/shared/laptop-flat-left.png",
-                                    USE_ALPHA);
+               "/images/shared/laptop-flat-left.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_flat_right ,DATA_PREFIX
-                                     "/images/shared/laptop-flat-right.png",
-                                     USE_ALPHA);
+               "/images/shared/laptop-flat-right.png",
+               USE_ALPHA);
 
   texture_load(&img_laptop_falling_left ,DATA_PREFIX
                "/images/shared/laptop-falling-left.png",
@@ -984,20 +987,20 @@ void loadshared(void)
   /* (Money) */
 
   texture_load(&img_money_left[0] ,DATA_PREFIX
-                                 "/images/shared/bag-left-0.png",
-                                 USE_ALPHA);
+               "/images/shared/bag-left-0.png",
+               USE_ALPHA);
 
   texture_load(&img_money_left[1] ,DATA_PREFIX
-                                 "/images/shared/bag-left-1.png",
-                                 USE_ALPHA);
+               "/images/shared/bag-left-1.png",
+               USE_ALPHA);
 
   texture_load(&img_money_right[0] ,DATA_PREFIX
-                                  "/images/shared/bag-right-0.png",
-                                  USE_ALPHA);
+               "/images/shared/bag-right-0.png",
+               USE_ALPHA);
 
   texture_load(&img_money_right[1] ,DATA_PREFIX
-                                  "/images/shared/bag-right-1.png",
-                                  USE_ALPHA);
+               "/images/shared/bag-right-1.png",
+               USE_ALPHA);
 
 
 
@@ -1012,29 +1015,29 @@ void loadshared(void)
   texture_load(&img_bullet ,DATA_PREFIX "/images/shared/bullet.png", USE_ALPHA);
 
   texture_load(&img_red_glow ,DATA_PREFIX "/images/shared/red-glow.png",
-                            USE_ALPHA);
+               USE_ALPHA);
 
 
 
   /* Distros: */
 
   texture_load(&img_distro[0] ,DATA_PREFIX "/images/shared/distro-0.png",
-                             USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_distro[1] ,DATA_PREFIX "/images/shared/distro-1.png",
-                             USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_distro[2] ,DATA_PREFIX "/images/shared/distro-2.png",
-                             USE_ALPHA);
+               USE_ALPHA);
 
   texture_load(&img_distro[3] ,DATA_PREFIX "/images/shared/distro-3.png",
-                             USE_ALPHA);
+               USE_ALPHA);
 
 
   /* Tux life: */
 
   texture_load(&tux_life ,DATA_PREFIX "/images/shared/tux-life.png",
-                        USE_ALPHA);
+               USE_ALPHA);
 
   /* Herring: */
 
@@ -1045,7 +1048,7 @@ void loadshared(void)
   /* Super background: */
 
   texture_load(&img_super_bkgd ,DATA_PREFIX "/images/shared/super-bkgd.png",
-                              IGNORE_ALPHA);
+               IGNORE_ALPHA);
 
 
   /* Sound effects: */
@@ -1199,7 +1202,7 @@ void drawshape(float x, float y, unsigned char c)
     texture_draw(&img_solid[3], x, y, NO_UPDATE);
   else if (c == '$')
     {
-      
+
       z = (frame / 2) % 6;
 
       if (z < 4)
@@ -1248,12 +1251,12 @@ unsigned char shape(float x, float y)
   xx = ((int)x / 32);
 
   if (yy >= 0 && yy < 15 && xx >= 0 && xx <= current_level.width)
-  {
-    c = current_level.tiles[yy][xx];
+    {
+      c = current_level.tiles[yy][xx];
     }
   else
     c = '.';
-    
+
   return(c);
 }
 
@@ -1509,7 +1512,7 @@ void trybumpbadguy(float x, float y)
 /* (Status): */
 void drawstatus(void)
 {
-int i;
+  int i;
 
   sprintf(str, "%d", score);
   drawtext("SCORE", 0, 0, letters_blue, NO_UPDATE, 1);
@@ -1532,6 +1535,15 @@ int i;
 
   drawtext("LIVES", screen->h, 20, letters_blue, NO_UPDATE, 1);
 
+  if(show_fps)
+    {
+      drawtext("FPS", screen->h, 40, letters_blue, NO_UPDATE, 1);
+      sprintf(str, "%f", fps_fps);
+      if(use_gl) /* FIXME: We need this check as text doesn't work in OpenGl mode. */
+        printf("%f\n",fps_fps);
+      drawtext(str, screen->h + 60, 40, letters_gold, NO_UPDATE, 1);
+    }
+
   for(i=0; i < tux.lives; ++i)
     {
       texture_draw(&tux_life,565+(18*i),20,NO_UPDATE);
@@ -1629,7 +1641,7 @@ void loadgame(char* filename)
     }
   else
     {
-    player_level_begin(&tux);
+      player_level_begin(&tux);
       set_defaults();
       loadlevel(&current_level,"default",level);
       arrays_free();
index cf9664d..b1ef329 100644 (file)
@@ -19,7 +19,7 @@
 SDL_Surface * screen;
 SDL_Surface * letters_black, * letters_gold, * letters_blue, * letters_red;
 
-int use_gl, use_joystick, use_fullscreen, debug_mode;
+int use_gl, use_joystick, use_fullscreen, debug_mode, show_fps;
 
 int game_started, level_editor_started;
 
index d5b13b4..1f95ff9 100644 (file)
 #include "scene.h"
 
 /* definitions to aid development */
-#define DONE_LEVELEDITOR    1
+#define DONE_LEVELEDITOR 1
 #define DONE_QUIT        2
-#define DONE_CHANGELEVEL  3
+#define DONE_CHANGELEVEL 3
 
 /* definitions that affect gameplay */
 #define KEY_CURSOR_SPEED 32
 #define KEY_CURSOR_FASTSPEED 64
+// when pagedown/up pressed speed:
+#define PAGE_CURSOR_SPEED 13*32
 
 #define CURSOR_LEFT_MARGIN 96
 #define CURSOR_RIGHT_MARGIN 512
@@ -83,6 +85,7 @@ void le_activate_bad_guys(void);
 int level;
 st_level current_level;
 char level_subset[100];
+int show_grid;
 
 int frame;
 texture_type selection;
@@ -138,7 +141,8 @@ int leveleditor()
   SDLMod keymod;
 
   strcpy(level_subset,"default");
-
+  show_grid = NO;
+  
   level = 1;
 
   initmenu();
@@ -206,8 +210,8 @@ int leveleditor()
                   else
                     cursor_x += KEY_CURSOR_FASTSPEED;
 
-                  if(cursor_x > (current_level.width*32) - 1)
-                    cursor_x = (current_level.width*32) - 1;
+                  if(cursor_x > (current_level.width*32) - 32)
+                    cursor_x = (current_level.width*32) - 32;
                   break;
                 case SDLK_UP:
                   if(fire == DOWN)
@@ -239,6 +243,24 @@ int leveleditor()
                 case SDLK_END:
                   cursor_x = (current_level.width * 32) - 32;
                   break;
+                case SDLK_PAGEUP:
+                  cursor_x -= PAGE_CURSOR_SPEED;
+
+                                                                       if(cursor_x < 0)
+                                                                               cursor_x = 0;
+                  break;
+                case SDLK_PAGEDOWN:
+                  cursor_x += PAGE_CURSOR_SPEED;
+
+                  if(cursor_x > (current_level.width*32) - 32)
+                    cursor_x = (current_level.width*32) - 32;
+                  break;
+                case SDLK_F9:
+                  if(!show_grid)
+                    show_grid = YES;
+                  else
+                    show_grid = NO;
+                  break;
                 case SDLK_PERIOD:
                   le_change(cursor_x, cursor_y, '.');
                   break;
@@ -435,6 +457,25 @@ int leveleditor()
         for (x = 0; x < 21; ++x)
           drawshape(x * 32, y * 32, current_level.tiles[y][x + (pos_x / 32)]);
 
+/* draw whats inside stuff when cursor is selecting those */
+int cursor_tile = current_level.tiles[cursor_y/32][cursor_x/32];
+switch(cursor_tile)
+       {
+       case 'B':
+               texture_draw(&img_mints, cursor_x - pos_x, cursor_y, NO_UPDATE);
+               break;
+       case '!':
+               texture_draw(&img_golden_herring, cursor_x - pos_x, cursor_y, NO_UPDATE);
+               break;
+       case 'x':
+       case 'y':
+       case 'A':
+               texture_draw(&img_distro[(frame / 5) % 4], cursor_x - pos_x, cursor_y, NO_UPDATE);
+               break;
+       default:
+               break;
+       }
+
       /* Draw the Bad guys: */
       for (i = 0; i < num_bad_guys; ++i)
         {
@@ -450,6 +491,14 @@ int leveleditor()
             texture_draw(&img_money_left[(frame / 5) % 2], ((int)(bad_guys[i].base.x - pos_x)/32)*32, bad_guys[i].base.y, NO_UPDATE);
         }
 
+/* draw a grid (if selected) */
+if(show_grid)
+       {
+       for(x = 0; x < 21; x++)
+               fillrect(x*32, 0, 1, 480, 225, 225, 225);
+       for(y = 0; y < 15; y++)
+               fillrect(0, y*32, 640, 1, 225, 225, 225);
+       }
 
       texture_draw(&selection, ((int)(cursor_x - pos_x)/32)*32, cursor_y, NO_UPDATE);
 
@@ -585,6 +634,7 @@ void showhelp()
                    "& - Water",
                    "0-2 - BadGuys",
                    "./Del - Remove tile",
+                   "F9 - Show/Hide Grid",
                    "Esc - Menu"};
 
 
index 4e1252b..ce4ee5c 100644 (file)
@@ -34,10 +34,7 @@ void player_init(player_type* pplayer)
   pplayer->duck = NO;
 
   pplayer->dying = NO;
-  pplayer->safe = TUX_SAFE_TIME;
-
   pplayer->jumping = NO;
-  pplayer->skidding = 0;
 
   pplayer->frame_main = 0;
   pplayer->frame = 0;
@@ -50,7 +47,77 @@ void player_init(player_type* pplayer)
   pplayer->input.right = UP;
   pplayer->input.up = UP;
 
+  pplayer->keymap.jump = SDLK_UP;
+  pplayer->keymap.duck = SDLK_DOWN;
+  pplayer->keymap.left = SDLK_LEFT;
+  pplayer->keymap.right = SDLK_RIGHT;
+  pplayer->keymap.fire = SDLK_LCTRL;
+  
   timer_init(&pplayer->invincible_timer);
+  timer_init(&pplayer->skidding_timer);
+  timer_init(&pplayer->safe_timer);
+}
+
+int player_keydown_event(player_type* pplayer, SDLKey key)
+{
+           if(key == pplayer->keymap.right)
+           {
+              pplayer->input.right = DOWN;
+              return YES;
+           }
+            else if( key == pplayer->keymap.left)
+           {
+              pplayer->input.left = DOWN;
+              return YES;
+           }
+            else if(key == pplayer->keymap.jump)
+           {
+              pplayer->input.up = DOWN;
+              return YES;
+           }
+            else if(key == pplayer->keymap.duck)
+           {
+              pplayer->input.down = DOWN;
+              return YES;
+            }
+           else if(key == pplayer->keymap.fire)
+           {
+              pplayer->input.fire = DOWN;
+              return YES;
+           }
+           else
+           return NO;
+}
+             
+int player_keyup_event(player_type* pplayer, SDLKey key)
+{
+           if(key == pplayer->keymap.right)
+           {
+              pplayer->input.right = UP;
+              return YES;
+           }
+            else if( key == pplayer->keymap.left)
+           {
+              pplayer->input.left = UP;
+              return YES;
+           }
+            else if(key == pplayer->keymap.jump)
+           {
+              pplayer->input.up = UP;
+              return YES;
+           }
+            else if(key == pplayer->keymap.duck)
+           {
+              pplayer->input.down = UP;
+              return YES;
+            }
+           else if(key == pplayer->keymap.fire)
+           {
+              pplayer->input.fire = UP;
+              return YES;
+           }
+           else
+           return NO;
 }
 
 void player_level_begin(player_type* pplayer)
@@ -59,6 +126,14 @@ void player_level_begin(player_type* pplayer)
   pplayer->base.y = 240;
   pplayer->base.xm = 0;
   pplayer->base.ym = 0;
+  
+  pplayer->input.down = UP;
+  pplayer->input.fire = UP;
+  pplayer->input.left = UP;
+  pplayer->input.old_fire = UP;
+  pplayer->input.right = UP;
+  pplayer->input.up = UP;
+
 }
 
 void player_action(player_type* pplayer)
@@ -362,8 +437,8 @@ void player_action(player_type* pplayer)
 
 
 
-  if (pplayer->safe > 0)
-    pplayer->safe--;
+  timer_check(&pplayer->safe_timer);
+    
 
   /* ---- DONE HANDLING TUX! --- */
 
@@ -393,11 +468,8 @@ void player_action(player_type* pplayer)
 
   /* Handle skidding: */
 
-  if (pplayer->skidding > 0)
-    {
-      pplayer->skidding--;
-    }
-
+  timer_check(&pplayer->skidding_timer);
+  
   /* End of level? */
 
   if (pplayer->base.x>= endpos && endpos != 0)
@@ -416,10 +488,10 @@ void player_input(player_type *pplayer)
     {
       if (pplayer->jumping == NO)
         {
-          if (pplayer->base.xm < -SKID_XM && !pplayer->skidding &&
+          if (pplayer->base.xm < -SKID_XM && !timer_started(&pplayer->skidding_timer) &&
               pplayer->dir == LEFT)
             {
-              pplayer->skidding = SKID_TIME;
+              timer_start(&pplayer->skidding_timer, SKID_TIME);
 
               play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
 
@@ -428,7 +500,7 @@ void player_input(player_type *pplayer)
         }
 
       if (pplayer->base.xm < 0 && !isice(pplayer->base.x, pplayer->base.y + 32) &&
-          !pplayer->skidding)
+          !timer_started(&pplayer->skidding_timer))
         {
           pplayer->base.xm = 0;
         }
@@ -470,17 +542,17 @@ void player_input(player_type *pplayer)
     {
       if (pplayer->jumping == NO)
         {
-          if (pplayer->base.xm > SKID_XM && !pplayer->skidding &&
+          if (pplayer->base.xm > SKID_XM && !timer_started(&pplayer->skidding_timer) &&
               pplayer->dir == RIGHT)
             {
-              pplayer->skidding = SKID_TIME;
+              timer_start(&pplayer->skidding_timer,SKID_TIME);
               play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
             }
           pplayer->dir = LEFT;
         }
 
       if (pplayer->base.xm > 0 && !isice(pplayer->base.x, pplayer->base.y + 32) &&
-          !pplayer->skidding)
+          !timer_started(&pplayer->skidding_timer))
         {
           pplayer->base.xm = 0;
         }
@@ -647,7 +719,7 @@ void player_grabdistros(player_type *pplayer)
 void player_draw(player_type* pplayer)
 {
 
-  if (pplayer->safe == 0 || (frame % 2) == 0)
+  if (!timer_started(&pplayer->safe_timer) || (frame % 2) == 0)
     {
       if (pplayer->size == SMALL)
         {
@@ -719,7 +791,7 @@ void player_draw(player_type* pplayer)
             {
               if (!pplayer->duck)
                 {
-                  if (!pplayer->skidding)
+                  if (!timer_started(&pplayer->skidding_timer))
                     {
                       if (!pplayer->jumping || pplayer->base.ym > 0)
                         {
@@ -788,7 +860,7 @@ void player_draw(player_type* pplayer)
 
               if (!pplayer->duck)
                 {
-                  if (!pplayer->skidding)
+                  if (!timer_started(&pplayer->skidding_timer))
                     {
                       if (!pplayer->jumping || pplayer->base.ym > 0)
                         {
@@ -867,7 +939,7 @@ void player_collision(player_type* pplayer, void* p_c_object, int c_object)
       /* Hurt the player if he just touched it: */
 
       if (!pbad_c->dying && !pplayer->dying &&
-          !pplayer->safe &&
+          !timer_started(&pplayer->safe_timer) &&
           pbad_c->mode != HELD)
         {
           if (pbad_c->mode == FLAT  && pplayer->input.fire != DOWN)
@@ -965,7 +1037,7 @@ void player_kill(player_type* pplayer, int mode)
 
       pplayer->size = SMALL;
 
-      pplayer->safe = TUX_SAFE_TIME;
+      timer_start(&pplayer->safe_timer,TUX_SAFE_TIME);
     }
   else
     {
@@ -981,7 +1053,9 @@ void player_dying(player_type *pplayer)
 
   --pplayer->lives;
   player_remove_powerups(pplayer);
-  pplayer->dying = 0;
+  pplayer->dying = NO;
+  
+  player_level_begin(pplayer);
 
 }
 
index e65d11b..b9ee3ae 100644 (file)
 
 /* Times: */
 
-#define TUX_SAFE_TIME 16
+#define TUX_SAFE_TIME 750
 #define TUX_INVINCIBLE_TIME 10000
 #define TIME_WARNING 20000     /* When to alert player they're low on time! */
 
+typedef struct player_keymap_type
+{
+ int jump;
+ int duck;
+ int left;
+ int right;
+ int fire;
+}
+player_keymap_type;
+
 typedef struct player_input_type
 {
  int right;
@@ -40,10 +50,9 @@ player_input_type;
 typedef struct player_type 
 {
  player_input_type input;
+ player_keymap_type keymap;
  int got_coffee;
  int size;
- int skidding;
- int safe;
  int duck;
  int dying;
  int dir;
@@ -54,6 +63,8 @@ typedef struct player_type
  base_type base;
  timer_type invincible_timer;
  timer_type jump_timer;
+ timer_type skidding_timer;
+ timer_type safe_timer;
 }
 player_type;
 
@@ -72,6 +83,8 @@ texture_type tux_life,
  bigcape_right[2],  bigcape_left[2];
 
 void player_init(player_type* pplayer);
+int player_keydown_event(player_type* pplayer, SDLKey key);
+int player_keyup_event(player_type* pplayer, SDLKey key);
 void player_level_begin(player_type* pplayer);
 void player_action(player_type* pplayer);
 void player_input(player_type* pplayer);
index b78058a..c01afc7 100644 (file)
@@ -58,6 +58,36 @@ void clearscreen(float r, float g, float b)
  
 }
 
+/* --- FILL A RECT --- */
+
+void fillrect(float x, float y, float w, float h, float r, float g, float b)
+{
+#ifndef NOOPENGL
+if(use_gl)
+       {
+       glBegin(GL_QUADS);
+               glColor3ub(r/256, g/256, b/256);
+               glVertex2i(x, y);
+               glVertex2i(x+w, y);
+               glVertex2i(x+w, y+h);
+               glVertex2i(x, y+h);
+       glEnd();
+       }
+else
+       {
+#endif
+       SDL_Rect rect;
+       rect.x = x;
+       rect.y = y;
+       rect.w = w;
+       rect.h = h;
+
+       SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
+#ifndef NOOPENGL
+       }
+#endif
+}
+
 
 /* --- UPDATE SCREEN --- */
 
@@ -117,13 +147,15 @@ void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int sha
 {
        /* i - helps to keep tracking of the all string length
                j - helps to keep track of the length of the current line */
-  int i, j;
+  int i, j, len;
   char c;
   SDL_Rect src, dest;
   
+  len = strlen(text);
+  
   /* For each letter in the string... */
   
-  for (i = 0; i < strlen(text); i++)
+  for (i = 0; i < len; ++i)
     {
       /* Set source rectangle: */
       
@@ -242,7 +274,7 @@ void drawtext(char * text, int x, int y, SDL_Surface * surf, int update, int sha
   
   if (update == UPDATE)
     {
-      dest.w = strlen(text) * 16 + 1;
+      dest.w = len * 16 + 1;
       
       if (dest.w > screen->w)
        dest.w = screen->w;
index 0a30328..0cd53ec 100644 (file)
@@ -29,6 +29,7 @@
 
 void load_and_display_image(char * file);
 void clearscreen(float r, float g, float b);
+void fillrect(float x, float y, float w, float h, float r, float g, float b);
 void updatescreen(void);
 void flipscreen(void);
 SDL_Surface * load_image(char * file, int use_alpha);
index 4f62180..23cebe5 100644 (file)
@@ -141,12 +141,8 @@ if(screen != NULL)
   st_video_setup_gl();
   else
   st_video_setup_sdl();
-
-  DEBUG_MSG("1");
   
   texture_setup();
-
-  DEBUG_MSG("2");
     
   /* Set window manager stuff: */
 
@@ -443,7 +439,7 @@ void parseargs(int argc, char * argv[])
 
   debug_mode = NO;
   use_fullscreen = NO;
-
+  show_fps = NO;
   use_gl = NO;    
 
 #ifndef NOSOUND
@@ -469,8 +465,14 @@ void parseargs(int argc, char * argv[])
 
           use_fullscreen = YES;
         }
+      else if (strcmp(argv[i], "--show-fps") == 0)
+        {
+          /* Use full screen: */
+
+          show_fps = YES;
+        }
       else if (strcmp(argv[i], "--opengl") == 0 ||
-          strcmp(argv[i], "-g") == 0)
+          strcmp(argv[i], "-gl") == 0)
         {
        #ifndef NOOPENGL
           /* Use OpengGL: */
index eff54e5..1242841 100644 (file)
@@ -166,7 +166,7 @@ void upgrade_action(upgrade_type *pupgrade)
 
           /* Off the screen?  Kill it! */
 
-          if (pupgrade->base.x < scroll_x)
+          if (pupgrade->base.x < scroll_x - pupgrade->base.width)
             pupgrade->base.alive = NO;
 
         }
index e18a475..1d230c2 100644 (file)
@@ -21,7 +21,7 @@
 double get_frame_ratio(base_type* pbase)
 {
   unsigned int cur_time = SDL_GetTicks();
-  double frame_ratio = (float)(cur_time-pbase->updated)/(float)(FRAME_RATE);
+  double frame_ratio = ((double)(cur_time-pbase->updated))/((double)FRAME_RATE);
   pbase->updated = cur_time;
   return (frame_ratio == 0 ? 1 : frame_ratio);
 }