- moved some global variables into a seperate class
authorIngo Ruhnke <grumbel@gmx.de>
Sun, 11 Apr 2004 15:07:29 +0000 (15:07 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sun, 11 Apr 2004 15:07:29 +0000 (15:07 +0000)
SVN-Revision: 476

src/badguy.cpp
src/gameloop.cpp
src/player.cpp
src/resources.cpp
src/scene.cpp
src/scene.h
src/special.cpp
src/world.cpp

index 36eb7a3..82529e9 100644 (file)
@@ -791,9 +791,10 @@ BadGuy::squish_me(Player* player)
 {
   make_player_jump(player);
     
-  World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier);
+  World::current()->add_score(base.x - scroll_x,
+                              base.y, 50 * player_status.score_multiplier);
   play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
-  score_multiplier++;
+  player_status.score_multiplier++;
 
   dying = DYING_SQUISHED;
   timer_start(&timer, 2000);
@@ -808,9 +809,9 @@ BadGuy::squish(Player* player)
     World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
     
     make_player_jump(player);
-    World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier);
+    World::current()->add_score(base.x - scroll_x, base.y, 50 * player_status.score_multiplier);
     play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
-    score_multiplier++;
+    player_status.score_multiplier++;
       
     remove_me();
     return;
@@ -849,14 +850,14 @@ BadGuy::squish(Player* player)
 
     make_player_jump(player);
              
-    World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier);
-    score_multiplier++;
+    World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier);
+    player_status.score_multiplier++;
     return;
   } else if(kind == BAD_FISH) {
     make_player_jump(player);
              
-    World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier);
-    score_multiplier++;
+    World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier);
+    player_status.score_multiplier++;
      
     // simply remove the fish...
     remove_me();
@@ -894,10 +895,10 @@ BadGuy::kill_me()
   /* Gain some points: */
   if (kind == BAD_BSOD)
     World::current()->add_score(base.x - scroll_x, base.y,
-                    50 * score_multiplier);
+                    50 * player_status.score_multiplier);
   else 
     World::current()->add_score(base.x - scroll_x, base.y,                                 
-                    25 * score_multiplier);
+                    25 * player_status.score_multiplier);
 
   /* Play death sound: */
   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
index 5016bae..fdae0a6 100644 (file)
@@ -249,11 +249,11 @@ GameSession::process_events()
                 break;
               case SDLK_END:
                 if(debug_mode)
-                  distros += 50;
+                  player_status.distros += 50;
                 break;
               case SDLK_SPACE:
                 if(debug_mode)
-                  next_level = 1;
+                  player_status.next_level = 1;
                 break;
               case SDLK_DELETE:
                 if(debug_mode)
@@ -269,7 +269,7 @@ GameSession::process_events()
                 break;
               case SDLK_s:
                 if(debug_mode)
-                  score += 1000;
+                  player_status.score += 1000;
               case SDLK_f:
                 if(debug_fps)
                   debug_fps = false;
@@ -342,16 +342,16 @@ GameSession::action()
 {
   Player& tux = *world->get_tux();
 
-  if (tux.is_dead() || next_level)
+  if (tux.is_dead() || player_status.next_level)
     {
       /* Tux either died, or reached the end of a level! */
       halt_music();
       
-      if (next_level)
+      if (player_status.next_level)
         {
           /* End of a level! */
           levelnb++;
-          next_level = 0;
+          player_status.next_level = 0;
           if(st_gl_mode != ST_GL_TEST)
             {
               drawresultscreen();
@@ -381,8 +381,8 @@ GameSession::action()
 
               if(st_gl_mode != ST_GL_TEST)
                 {
-                  if (score > hs_score)
-                    save_hs(score);
+                  if (player_status.score > hs_score)
+                    save_hs(player_status.score);
                 }
 
               world->get_level()->free_gfx();
@@ -660,7 +660,7 @@ GameSession::drawstatus()
   Player& tux = *world->get_tux();
   char str[60];
 
-  sprintf(str, "%d", score);
+  sprintf(str, "%d", player_status.score);
   text_draw(&white_text, "SCORE", 0, 0, 1);
   text_draw(&gold_text, str, 96, 0, 1);
 
@@ -682,7 +682,7 @@ GameSession::drawstatus()
       text_draw(&gold_text, str, 304, 0, 1);
     }
 
-  sprintf(str, "%d", distros);
+  sprintf(str, "%d", player_status.distros);
   text_draw(&white_text, "DISTROS", screen->h, 0, 1);
   text_draw(&gold_text, str, 608, 0, 1);
 
@@ -710,10 +710,10 @@ GameSession::drawendscreen()
 
   text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "SCORE: %d", score);
+  sprintf(str, "SCORE: %d", player_status.score);
   text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "DISTROS: %d", distros);
+  sprintf(str, "DISTROS: %d", player_status.distros);
   text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();
@@ -731,10 +731,10 @@ GameSession::drawresultscreen(void)
 
   text_drawf(&blue_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "SCORE: %d", score);
+  sprintf(str, "SCORE: %d", player_status.score);
   text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "DISTROS: %d", distros);
+  sprintf(str, "DISTROS: %d", player_status.distros);
   text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();
index 5ff28ce..1fbe91c 100644 (file)
@@ -201,7 +201,7 @@ Player::action()
 
           physic.enable_gravity(false);
           /* Reset score multiplier (for multi-hits): */
-          score_multiplier = 1;
+          player_status.score_multiplier = 1;
         }
 
       if(jumped_in_solid)
@@ -289,7 +289,7 @@ Player::action()
   if (base.x >= World::current()->get_level()->endpos
       && World::current()->get_level()->endpos != 0)
     {
-      next_level = 1;
+      player_status.next_level = 1;
     }
 
 }
@@ -830,7 +830,7 @@ Player::collision(void* p_c_object, int c_object)
                       play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
                       World::current()->add_score(pbad_c->base.x - scroll_x,
                                                   pbad_c->base.y,
-                                                  25 * score_multiplier);
+                                                  25 * player_status.score_multiplier);
                     }
                 }
             }
@@ -845,7 +845,7 @@ Player::collision(void* p_c_object, int c_object)
                   pbad_c->kill_me();
                 }
             }
-          score_multiplier++;
+          player_status.score_multiplier++;
         }
       break;
     default:
index 41e1773..b02fe49 100644 (file)
@@ -17,7 +17,6 @@ texture_type img_box_full;
 texture_type img_box_empty;
 texture_type img_mints;
 texture_type img_coffee;
-texture_type img_super_bkgd;
 texture_type img_red_glow;
 
 /* Load graphics/sounds shared between all levels: */
@@ -284,12 +283,6 @@ void loadshared()
                USE_ALPHA);
 
 
-  /* Super background: */
-
-  texture_load(&img_super_bkgd, datadir + "/images/shared/super-bkgd.png",
-               IGNORE_ALPHA);
-
-
   /* Sound effects: */
 
   /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
index 82826d5..d916e50 100644 (file)
 #include <stdlib.h>
 #include "scene.h"
 
-int score;
-int distros;
-int next_level;
-int score_multiplier;
-timer_type  super_bkgd_timer;
+PlayerStatus player_status;
 
 // FIXME: Move this into a view class
 float scroll_x;
index daaa4e6..435dc2d 100644 (file)
 #define FRAME_RATE 10 // 100 Frames per second (10ms)
 
 // Player stats
-extern int  score;
-extern int  distros;
-extern int  next_level;
-extern int  score_multiplier;
+struct PlayerStatus
+{
+  int  score;
+  int  distros;
+  int  next_level;
+  int  score_multiplier;
+};
+
+extern PlayerStatus player_status;
 
 extern timer_type  super_bkgd_timer;
 extern float scroll_x;
index ff1db13..218751e 100644 (file)
@@ -261,19 +261,16 @@ Upgrade::collision(void* p_c_object, int c_object)
               pplayer->base.y += 32;
               pplayer->duck = true;
             }
-          timer_start(&super_bkgd_timer, 350);
         }
       else if (kind == UPGRADE_COFFEE)
         {
           play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
           pplayer->got_coffee = true;
-          timer_start(&super_bkgd_timer, 250);
         }
       else if (kind == UPGRADE_HERRING)
         {
           play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
           timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
-          timer_start(&super_bkgd_timer, 250);
           /* play the herring song ^^ */
           if (get_current_music() != HURRYUP_MUSIC)
             {
index d4188cd..57d1b8a 100644 (file)
@@ -56,8 +56,7 @@ World::set_defaults()
   // Set defaults: 
   scroll_x = 0;
 
-  score_multiplier = 1;
-  timer_init(&super_bkgd_timer, true);
+  player_status.score_multiplier = 1;
 
   counting_distros = false;
   distro_counter = 0;
@@ -128,24 +127,18 @@ World::draw()
 {
   int y,x;
 
-  /* Draw screen: */
-  if(timer_check(&super_bkgd_timer))
-    texture_draw(&img_super_bkgd, 0, 0);
+  /* Draw the real background */
+  if(get_level()->bkgd_image[0] != '\0')
+    {
+      int s = (int)scroll_x / 30;
+      texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h);
+      texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h);
+    }
   else
     {
-      /* Draw the real background */
-      if(get_level()->bkgd_image[0] != '\0')
-        {
-          int s = (int)scroll_x / 30;
-          texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h);
-          texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h);
-        }
-      else
-        {
-          clearscreen(level->bkgd_red, level->bkgd_green, level->bkgd_blue);
-        }
+      clearscreen(level->bkgd_red, level->bkgd_green, level->bkgd_blue);
     }
-
+    
   /* Draw particle systems (background) */
   std::vector<ParticleSystem*>::iterator p;
   for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
@@ -346,7 +339,7 @@ World::collision_handler()
 void
 World::add_score(float x, float y, int s)
 {
-  score += s;
+  player_status.score += s;
 
   FloatingScore new_floating_score;
   new_floating_score.init(x,y,s);
@@ -439,8 +432,8 @@ World::trybreakbrick(float x, float y, bool small)
             plevel->change(x, y, TM_IA, tile->next_tile);
 
           play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
-          score = score + SCORE_DISTRO;
-          distros++;
+          player_status.score = player_status.score + SCORE_DISTRO;
+          player_status.distros++;
         }
       else if (!small)
         {
@@ -454,7 +447,7 @@ World::trybreakbrick(float x, float y, bool small)
           
           /* Get some score: */
           play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
-          score = score + SCORE_BRICK;
+          player_status.score = player_status.score + SCORE_BRICK;
         }
     }
 }
@@ -478,8 +471,8 @@ World::tryemptybox(float x, float y, int col_side)
     case 1: // Box with a distro!
       add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32);
       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
-      score = score + SCORE_DISTRO;
-      distros++;
+      player_status.score = player_status.score + SCORE_DISTRO;
+      player_status.distros++;
       break;
 
     case 2: // Add an upgrade!
@@ -517,8 +510,8 @@ World::trygrabdistro(float x, float y, int bounciness)
                                   (int)(y / 32) * 32);
         }
 
-      score = score + SCORE_DISTRO;
-      distros++;
+      player_status.score = player_status.score + SCORE_DISTRO;
+      player_status.distros++;
     }
 }