converted game object arrays to std::vector
authorTobias Gläßer <tobi.web@gmx.de>
Sun, 21 Mar 2004 21:20:08 +0000 (21:20 +0000)
committerTobias Gläßer <tobi.web@gmx.de>
Sun, 21 Mar 2004 21:20:08 +0000 (21:20 +0000)
SVN-Revision: 304

src/badguy.cpp
src/collision.cpp
src/gameloop.cpp
src/leveleditor.cpp
src/scene.cpp
src/scene.h
src/special.cpp
src/type.h
src/world.cpp

index f09a32e..1d69e84 100644 (file)
@@ -34,7 +34,6 @@ void badguy_init(bad_guy_type* pbad, float x, float y, int kind)
 {
   pbad->base.width = 32;
   pbad->base.height = 32;
-  pbad->base.alive = YES;
   pbad->mode = NORMAL;
   pbad->dying = NO;
   pbad->kind = kind;
@@ -52,8 +51,6 @@ void badguy_init(bad_guy_type* pbad, float x, float y, int kind)
 void badguy_action(bad_guy_type* pbad)
 {
 
-  if (pbad->base.alive)
-    {
       if (pbad->seen)
         {
           if (pbad->kind == BAD_BSOD)
@@ -79,8 +76,8 @@ void badguy_action(bad_guy_type* pbad)
               if (pbad->dying != FALLING)
                 collision_swept_object_map(&pbad->old_base,&pbad->base);
               if (pbad->base.y > screen->h)
-                pbad->base.alive = NO;
-
+                bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+               
               /* Bump into things horizontally: */
 
               if (!pbad->dying)
@@ -132,7 +129,7 @@ void badguy_action(bad_guy_type* pbad)
                 }
 
               if (pbad->base.y > screen->h)
-                pbad->base.alive = NO;
+                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
             }
           else if (pbad->kind == BAD_LAPTOP)
             {
@@ -194,7 +191,7 @@ void badguy_action(bad_guy_type* pbad)
               if (pbad->dying != FALLING)
                 collision_swept_object_map(&pbad->old_base,&pbad->base);
               if (pbad->base.y > screen->h)
-                pbad->base.alive = NO;
+                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
               /* Bump into things horizontally: */
 
               /* Bump into things horizontally: */
@@ -279,7 +276,7 @@ void badguy_action(bad_guy_type* pbad)
                 collision_swept_object_map(&pbad->old_base,&pbad->base);
 
               if (pbad->base.y > screen->h)
-                pbad->base.alive = NO;
+                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
 
               if(physic_get_state(&pbad->physic) == -1)
                 {
@@ -324,9 +321,6 @@ void badguy_action(bad_guy_type* pbad)
       else if (pbad->kind == -1)
       {}
 
-
-    }
-
   /* Handle mode timer: */
 
   if (pbad->mode == FLAT && pbad->mode != HELD)
@@ -349,14 +343,14 @@ void badguy_action(bad_guy_type* pbad)
     {
       /* Remove it if time's up: */
       if(!timer_check(&pbad->timer))
-        pbad->base.alive = NO;
+        bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
     }
 
 
   /* Remove if it's far off the screen: */
 
   if (pbad->base.x < scroll_x - OFFSCREEN_DISTANCE)
-    pbad->base.alive = NO;
+      bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
   else /* !seen */
     {
       /* Once it's on screen, it's activated! */
@@ -369,8 +363,7 @@ void badguy_action(bad_guy_type* pbad)
 
 void badguy_draw(bad_guy_type* pbad)
 {
-  if (pbad->base.alive &&
-      pbad->base.x > scroll_x - 32 &&
+  if (pbad->base.x > scroll_x - 32 &&
       pbad->base.x < scroll_x + screen->w)
     {
       if (pbad->kind == BAD_BSOD)
index 01ae29b..95ceae9 100644 (file)
@@ -223,16 +223,14 @@ return 0;
 
 void collision_handler()
 {
-  int i,j;
+  unsigned int i,j;
 
   /* CO_BULLET & CO_BADGUY check */
-  for(i = 0; i < num_bullets; ++i)
+  for(i = 0; i < bullets.size(); ++i)
     {
-      if(bullets[i].base.alive)
-        {
-          for(j = 0; j < num_bad_guys; ++j)
+          for(j = 0; j < bad_guys.size(); ++j)
             {
-              if(bad_guys[j].dying == NO && bad_guys[j].base.alive)
+              if(bad_guys[j].dying == NO)
                 {
                   if(rectcollision(&bullets[i].base,&bad_guys[j].base) == YES)
                     {
@@ -242,17 +240,16 @@ void collision_handler()
                     }
                 }
             }
-        }
     }
 
   /* CO_BADGUY & CO_BADGUY check */
-  for(i = 0; i < num_bad_guys; ++i)
+  for(i = 0; i < bad_guys.size(); ++i)
     {
-      if(bad_guys[i].base.alive && bad_guys[i].dying == NO)
+      if(bad_guys[i].dying == NO)
         {
-          for(j = i+1; j < num_bad_guys; ++j)
+          for(j = i+1; j < bad_guys.size(); ++j)
             {
-              if(j != i && bad_guys[j].base.alive && bad_guys[j].dying == NO)
+              if(j != i && bad_guys[j].dying == NO)
                 {
                   if(rectcollision(&bad_guys[i].base,&bad_guys[j].base) == YES)
                     {
@@ -268,10 +265,8 @@ void collision_handler()
 
 
   /* CO_BADGUY & CO_PLAYER check */
-  for(i = 0; i < num_bad_guys; ++i)
+  for(i = 0; i < bad_guys.size(); ++i)
     {
-      if(bad_guys[i].base.alive)
-        {
           if(bad_guys[i].dying == NO && rectcollision_offset(&bad_guys[i].base,&tux.base,0,0) == YES )
             {
               /* We have detected a collision and now call the collision functions of the collided objects. */
@@ -286,21 +281,16 @@ void collision_handler()
                   player_collision(&tux, &bad_guys[i], CO_BADGUY);
                 }
             }
-        }
     }
 
   /* CO_UPGRADE & CO_PLAYER check */
-  for(i = 0; i < num_upgrades; ++i)
+  for(i = 0; i < upgrades.size(); ++i)
     {
-      if(upgrades[i].base.alive)
-        {
           if(rectcollision(&upgrades[i].base,&tux.base) == YES)
             {
               /* We have detected a collision and now call the collision functions of the collided objects. */
               upgrade_collision(&upgrades[i], &tux, CO_PLAYER);
             }
-
-        }
     }
 
 }
index 0f383df..2d687ef 100644 (file)
@@ -384,7 +384,7 @@ int game_action(void)
 
   /* Handle bouncy distros: */
 
-  for (i = 0; i < num_bouncy_distros; i++)
+  for (i = 0; i < bouncy_distros.size(); i++)
     {
       bouncy_distro_action(&bouncy_distros[i]);
     }
@@ -392,7 +392,7 @@ int game_action(void)
 
   /* Handle broken bricks: */
 
-  for (i = 0; i < num_broken_bricks; i++)
+  for (i = 0; i < broken_bricks.size(); i++)
     {
       broken_brick_action(&broken_bricks[i]);
     }
@@ -411,7 +411,7 @@ int game_action(void)
 
   /* Handle bouncy bricks: */
 
-  for (i = 0; i < num_bouncy_bricks; i++)
+  for (i = 0; i < bouncy_bricks.size(); i++)
     {
       bouncy_brick_action(&bouncy_bricks[i]);
     }
@@ -419,7 +419,7 @@ int game_action(void)
 
   /* Handle floating scores: */
 
-  for (i = 0; i < num_floating_scores; i++)
+  for (i = 0; i < floating_scores.size(); i++)
     {
       floating_score_action(&floating_scores[i]);
     }
@@ -427,14 +427,14 @@ int game_action(void)
 
   /* Handle bullets: */
 
-  for (i = 0; i < num_bullets; ++i)
+  for (i = 0; i < bullets.size(); ++i)
     {
       bullet_action(&bullets[i]);
     }
 
   /* Handle upgrades: */
 
-  for (i = 0; i < num_upgrades; i++)
+  for (i = 0; i < upgrades.size(); i++)
     {
       upgrade_action(&upgrades[i]);
     }
@@ -442,7 +442,7 @@ int game_action(void)
 
   /* Handle bad guys: */
 
-  for (i = 0; i < num_bad_guys; i++)
+  for (i = 0; i < bad_guys.size(); i++)
     {
       badguy_action(&bad_guys[i]);
     }
@@ -494,7 +494,7 @@ void game_draw(void)
 
   /* (Bouncy bricks): */
 
-  for (i = 0; i < num_bouncy_bricks; ++i)
+  for (i = 0; i < bouncy_bricks.size(); ++i)
     {
       bouncy_brick_draw(&bouncy_bricks[i]);
     }
@@ -502,7 +502,7 @@ void game_draw(void)
 
   /* (Bad guys): */
 
-  for (i = 0; i < num_bad_guys; ++i)
+  for (i = 0; i < bad_guys.size(); ++i)
     {
       badguy_draw(&bad_guys[i]);
     }
@@ -513,14 +513,14 @@ void game_draw(void)
 
   /* (Bullets): */
 
-  for (i = 0; i < num_bullets; ++i)
+  for (i = 0; i < bullets.size(); ++i)
     {
       bullet_draw(&bullets[i]);
     }
 
   /* (Floating scores): */
 
-  for (i = 0; i < num_floating_scores; ++i)
+  for (i = 0; i < floating_scores.size(); ++i)
     {
       floating_score_draw(&floating_scores[i]);
     }
@@ -528,7 +528,7 @@ void game_draw(void)
 
   /* (Upgrades): */
 
-  for (i = 0; i < num_upgrades; ++i)
+  for (i = 0; i < upgrades.size(); ++i)
     {
       upgrade_draw(&upgrades[i]);
     }
@@ -536,7 +536,7 @@ void game_draw(void)
 
   /* (Bouncy distros): */
 
-  for (i = 0; i < num_bouncy_distros; ++i)
+  for (i = 0; i < bouncy_distros.size(); ++i)
     {
       bouncy_distro_draw(&bouncy_distros[i]);
     }
@@ -544,7 +544,7 @@ void game_draw(void)
 
   /* (Broken bricks): */
 
-  for (i = 0; i < num_broken_bricks; ++i)
+  for (i = 0; i < broken_bricks.size(); ++i)
     {
       broken_brick_draw(&broken_bricks[i]);
     }
@@ -1570,10 +1570,9 @@ void trybumpbadguy(float x, float y)
 
   /* Bad guys: */
 
-  for (i = 0; i < num_bad_guys; i++)
+  for (i = 0; i < bad_guys.size(); i++)
     {
-      if (bad_guys[i].base.alive &&
-          bad_guys[i].base.x >= x - 32 && bad_guys[i].base.x <= x + 32 &&
+      if (bad_guys[i].base.x >= x - 32 && bad_guys[i].base.x <= x + 32 &&
           bad_guys[i].base.y >= y - 16 && bad_guys[i].base.y <= y + 16)
         {
           if (bad_guys[i].kind == BAD_BSOD ||
@@ -1589,9 +1588,9 @@ void trybumpbadguy(float x, float y)
 
   /* Upgrades: */
 
-  for (i = 0; i < num_upgrades; i++)
+  for (i = 0; i < upgrades.size(); i++)
     {
-      if (upgrades[i].base.alive && upgrades[i].base.height == 32 &&
+      if (upgrades[i].base.height == 32 &&
           upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 &&
           upgrades[i].base.y >= y - 16 && upgrades[i].base.y <= y + 16)
         {
index 09b6b85..0ecf74a 100644 (file)
@@ -859,10 +859,8 @@ void le_drawlevel()
       }
 
   /* Draw the Bad guys: */
-  for (i = 0; i < num_bad_guys; ++i)
+  for (i = 0; i < bad_guys.size(); ++i)
     {
-      if(bad_guys[i].base.alive == NO)
-        continue;
       /* to support frames: img_bsod_left[(frame / 5) % 4] */
       if(bad_guys[i].kind == BAD_BSOD)
         texture_draw(&img_bsod_left[(le_frame / 5) % 4], bad_guys[i].base.x - pos_x, bad_guys[i].base.y, NO_UPDATE);
@@ -1328,10 +1326,9 @@ void le_change(float x, float y, unsigned char c)
           xx = ((int)x / 32);
 
           /* if there is a bad guy over there, remove it */
-          for(i = 0; i < num_bad_guys; ++i)
-            if (bad_guys[i].base.alive)
+          for(i = 0; i < bad_guys.size(); ++i)
               if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32)
-                bad_guys[i].base.alive = NO;
+                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(&bad_guys[i]));
 
           if(c == '0')  /* if it's a bad guy */
             add_bad_guy(xx*32, yy*32, BAD_BSOD);
@@ -1369,11 +1366,10 @@ void le_change(float x, float y, unsigned char c)
           y2 /= 32;
 
           /* if there is a bad guy over there, remove it */
-          for(i = 0; i < num_bad_guys; ++i)
-            if(bad_guys[i].base.alive)
+          for(i = 0; i < bad_guys.size(); ++i)
               if(bad_guys[i].base.x/32 >= x1 && bad_guys[i].base.x/32 <= x2
                   && bad_guys[i].base.y/32 >= y1 && bad_guys[i].base.y/32 <= y2)
-                bad_guys[i].base.alive = NO;
+                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(&bad_guys[i]));
 
           for(xx = x1; xx <= x2; xx++)
             for(yy = y1; yy <= y2; yy++)
index 1748e45..2fdacb7 100644 (file)
@@ -17,20 +17,13 @@ int score, distros, level, next_level, game_pause, quit, score_multiplier, endpo
 timer_type  super_bkgd_timer;
 float scroll_x;
 int frame;
-bouncy_distro_type *bouncy_distros;
-broken_brick_type *broken_bricks;
-bouncy_brick_type *bouncy_bricks;
-bad_guy_type *bad_guys;
-floating_score_type *floating_scores;
-upgrade_type *upgrades;
-bullet_type *bullets;
-int num_bad_guys;
-int num_bouncy_distros;
-int num_broken_bricks;
-int num_bouncy_bricks;
-int num_floating_scores;
-int num_upgrades;
-int num_bullets;
+std::vector<bouncy_distro_type> bouncy_distros;
+std::vector<broken_brick_type> broken_bricks;
+std::vector<bouncy_brick_type> bouncy_bricks;
+std::vector<bad_guy_type> bad_guys;
+std::vector<floating_score_type> floating_scores;
+std::vector<upgrade_type> upgrades;
+std::vector<bullet_type> bullets;
 player_type tux;
 texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
 timer_type time_left;
@@ -39,32 +32,18 @@ double frame_ratio;
 /* Initialize all 'dynamic' arrays */
 void arrays_init(void)
 {
-num_bad_guys = 0;
-num_bouncy_distros = 0;
-num_broken_bricks = 0;
-num_bouncy_bricks = 0;
-num_floating_scores = 0;
-num_upgrades = 0;
-num_bullets = 0;
-bad_guys = NULL;
-bouncy_distros = NULL;
-broken_bricks = NULL;
-bouncy_bricks = NULL;
-floating_scores = NULL;
-upgrades = NULL;
-bullets = NULL;
 }
 
 /* Free memory of 'dynamic' arrays */
 void arrays_free(void)
 {
-free(bad_guys);
-free(bouncy_distros);
-free(broken_bricks);
-free(bouncy_bricks);
-free(floating_scores);
-free(upgrades);
-free(bullets);
+bad_guys.clear();
+bouncy_distros.clear();
+broken_bricks.clear();
+bouncy_bricks.clear();
+floating_scores.clear();
+upgrades.clear();
+bullets.clear();
 }
 
 void set_defaults(void)
@@ -89,63 +68,23 @@ void set_defaults(void)
 
 void add_score(float x, float y, int s)
 {
-  int i, found;
-
-
-  /* Add the score: */
+ /* Add the score: */
 
   score += s;
 
-
-  /* Add a floating score thing to the game: */
-
-  found = -1;
-
-  for (i = 0; i < num_floating_scores && found == -1; i++)
-    {
-      if (!floating_scores[i].base.alive)
-        found = i;
-    }
-    
-  if (found == -1)
-  {
-  ++num_floating_scores;
-  floating_scores = (floating_score_type*) realloc(floating_scores,num_floating_scores*sizeof(floating_score_type));
-  floating_score_init(&floating_scores[num_floating_scores-1],x,y,s);
-  found = -1;
-  }
-
-  if (found != -1)
-    {
-       floating_score_init(&floating_scores[found],x,y,s);
-    }
+  floating_score_type new_floating_score;
+  floating_score_init(&new_floating_score,x,y,s);
+  floating_scores.push_back(new_floating_score);
 }
 
 /* Add a bouncy distro: */
 
 void add_bouncy_distro(float x, float y)
 {
-  int i, found;
-
-  found = -1;
-
-  for (i = 0; i < num_bouncy_distros && found == -1; i++)
-    {
-      if (!bouncy_distros[i].base.alive)
-        found = i;
-    }
-    
-  if (found == -1)
-  {
-  ++num_bouncy_distros;
-  bouncy_distros = (bouncy_distro_type*) realloc(bouncy_distros,num_bouncy_distros*sizeof(bouncy_distro_type));
-  found = num_bouncy_distros - 1;
-  }
-    
-  if (found != -1)
-    {
-       bouncy_distro_init(&bouncy_distros[found],x,y);
-    }
+
+  bouncy_distro_type new_bouncy_distro;
+  bouncy_distro_init(&new_bouncy_distro,x,y);
+  bouncy_distros.push_back(new_bouncy_distro);
 }
 
 
@@ -165,27 +104,9 @@ void add_broken_brick(float x, float y)
 
 void add_broken_brick_piece(float x, float y, float xm, float ym)
 {
-  int i, found;
-
-  found = -1;
-
-  for (i = 0; i < num_broken_bricks && found == -1; i++)
-    {
-      if (!broken_bricks[i].base.alive)
-        found = i;
-    }
-
-  if (found == -1)
-  {
-  ++num_broken_bricks;
-  broken_bricks = (broken_brick_type*) realloc(broken_bricks,num_broken_bricks*sizeof(broken_brick_type));
-  found = num_broken_bricks - 1;
-  }
-
-  if (found != -1)
-    {
-       broken_brick_init(&broken_bricks[found], x, y, xm, ym);
-    }
+  broken_brick_type new_broken_brick;
+  broken_brick_init(&new_broken_brick,x,y,xm,ym);
+  broken_bricks.push_back(new_broken_brick);
 }
 
 
@@ -193,27 +114,9 @@ void add_broken_brick_piece(float x, float y, float xm, float ym)
 
 void add_bouncy_brick(float x, float y)
 {
-  int i, found;
-
-  found = -1;
-
-  for (i = 0; i < num_bouncy_bricks && found == -1; i++)
-    {
-      if (!bouncy_bricks[i].base.alive)
-        found = i;
-    }
-    
-  if (found == -1)
-  {
-  ++num_bouncy_bricks;
-  bouncy_bricks = (bouncy_brick_type*) realloc(bouncy_bricks,num_bouncy_bricks*sizeof(bouncy_brick_type));
-  found = num_bouncy_bricks - 1;
-  }
-
-  if (found != -1)
-    {
-      bouncy_brick_init(&bouncy_bricks[found],x,y);
-    }
+  bouncy_brick_type new_bouncy_brick;
+  bouncy_brick_init(&new_bouncy_brick,x,y);
+  bouncy_bricks.push_back(new_bouncy_brick);
 }
 
 
@@ -221,82 +124,28 @@ void add_bouncy_brick(float x, float y)
 
 void add_bad_guy(float x, float y, int kind)
 {
-  int i, found;
-
-  found = -1;
-
-  for (i = 0; i < num_bad_guys && found == -1; i++)
-    {
-      if (!bad_guys[i].base.alive)
-        found = i;
-    }
-  if (found == -1)
-  {
-  ++num_bad_guys;
-  bad_guys = (bad_guy_type*) realloc(bad_guys,num_bad_guys*sizeof(bad_guy_type));
-  found = num_bad_guys - 1;
-  }
-
-  if (found != -1)
-    {
-       badguy_init(&bad_guys[found], x, y, kind);
-    }
+  bad_guy_type new_bad_guy;
+  badguy_init(&new_bad_guy,x,y,kind);
+  bad_guys.push_back(new_bad_guy);
 }
 
 /* Add an upgrade: */
 
 void add_upgrade(float x, float y, int dir, int kind)
 {
-  int i, found;
-
-  found = -1;
-
-  for (i = 0; i < num_upgrades && found == -1; i++)
-    {
-      if (!upgrades[i].base.alive)
-        found = i;
-    }
-
-  if (found == -1)
-  {
-  ++num_upgrades;
-  upgrades = (upgrade_type*) realloc(upgrades,num_upgrades*sizeof(upgrade_type));
-  found = num_upgrades - 1;
-  }
-
-  if (found != -1)
-    {
-      upgrade_init(&upgrades[found], x, y, dir, kind);
-    }
+  upgrade_type new_upgrade;
+  upgrade_init(&new_upgrade,x,y,dir,kind);
+  upgrades.push_back(new_upgrade);
 }
 
 /* Add a bullet: */
 
 void add_bullet(float x, float y, float xm, int dir)
 {
-  int i, found;
+  bullet_type new_bullet;
+  bullet_init(&new_bullet,x,y,xm,dir);
+  bullets.push_back(new_bullet);
   
-  found = -1;
-
-  for (i = 0; i < num_bullets && found == -1; i++)
-    {
-      if (!bullets[i].base.alive)
-        found = i;
-    }
-
-  if (found == -1)
-  {
-  ++num_bullets;
-  bullets = (bullet_type*) realloc(bullets,num_bullets*sizeof(bullet_type));
-  found = num_bullets - 1;
-  }
-
-  if (found != -1)
-    {
-      bullet_init(&bullets[found], x, y, xm, dir);
-
-      play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
-    }
+  play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
 }
 
index d4ec0db..9aa0529 100644 (file)
@@ -26,20 +26,13 @@ extern int score, distros, level, next_level, game_pause, quit, score_multiplier
 extern timer_type  super_bkgd_timer;
 extern float scroll_x;
 extern int frame;
-extern bouncy_distro_type *bouncy_distros;
-extern broken_brick_type *broken_bricks;
-extern bouncy_brick_type *bouncy_bricks;
-extern bad_guy_type *bad_guys;
-extern floating_score_type *floating_scores;
-extern upgrade_type *upgrades;
-extern bullet_type *bullets;
-extern int num_bad_guys;
-extern int num_bouncy_distros;
-extern int num_broken_bricks;
-extern int num_bouncy_bricks;
-extern int num_floating_scores;
-extern int num_upgrades;
-extern int num_bullets;
+extern std::vector<bouncy_distro_type> bouncy_distros;
+extern std::vector<broken_brick_type> broken_bricks;
+extern std::vector<bouncy_brick_type> bouncy_bricks;
+extern std::vector<bad_guy_type> bad_guys;
+extern std::vector<floating_score_type> floating_scores;
+extern std::vector<upgrade_type> upgrades;
+extern std::vector<bullet_type> bullets;
 extern player_type tux;
 extern texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
 extern timer_type time_left;
index 8121f7e..9b1b5cc 100644 (file)
@@ -33,7 +33,6 @@ void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
 {
   pbullet->base.width = 4;
   pbullet->base.height = 4;
-  pbullet->base.alive = YES;
 
   if (dir == RIGHT)
     {
@@ -53,8 +52,6 @@ void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
 
 void bullet_action(bullet_type* pbullet)
 {
-  if (pbullet->base.alive)
-    {
       pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
       pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
 
@@ -75,16 +72,14 @@ void bullet_action(bullet_type* pbullet)
          issolid(pbullet->base.x + 4, pbullet->base.y + 2) ||
          issolid(pbullet->base.x, pbullet->base.y + 2))
         {
-          pbullet->base.alive = NO;
+          bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet));
         }
-    }
 
 }
 
 void bullet_draw(bullet_type* pbullet)
 {
-  if (pbullet->base.alive  &&
-      pbullet->base.x >= scroll_x - pbullet->base.width &&
+  if (pbullet->base.x >= scroll_x - pbullet->base.width &&
       pbullet->base.x <= scroll_x + screen->w)
     {
       texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y,
@@ -96,7 +91,7 @@ void bullet_collision(bullet_type* pbullet, int c_object)
 {
 
   if(c_object == CO_BADGUY)
-    pbullet->base.alive = NO;
+    bullets.erase(static_cast<std::vector<bullet_type>::iterator>(pbullet));
 
 }
 
@@ -104,7 +99,6 @@ void upgrade_init(upgrade_type *pupgrade, float x, float y, int dir, int kind)
 {
   pupgrade->base.width = 32;
   pupgrade->base.height = 0;
-  pupgrade->base.alive = YES;
   pupgrade->kind = kind;
   pupgrade->base.x = x;
   pupgrade->base.y = y;
@@ -120,8 +114,7 @@ void upgrade_init(upgrade_type *pupgrade, float x, float y, int dir, int kind)
 void upgrade_action(upgrade_type *pupgrade)
 {
 
-  if (pupgrade->base.alive)
-    {
+
       if (pupgrade->base.height < 32)
         {
           /* Rise up! */
@@ -145,9 +138,9 @@ void upgrade_action(upgrade_type *pupgrade)
               /* Off the screen?  Kill it! */
 
               if (pupgrade->base.x < scroll_x - pupgrade->base.width)
-                pupgrade->base.alive = NO;
+                upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
               if (pupgrade->base.y > screen->h)
-                pupgrade->base.alive = NO;
+                upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
 
               if (issolid(pupgrade->base.x + 1, pupgrade->base.y + 32.) ||
                   issolid(pupgrade->base.x + 31., pupgrade->base.y + 32.))
@@ -182,14 +175,11 @@ void upgrade_action(upgrade_type *pupgrade)
             }
 
         }
-    }
 }
 
 void upgrade_draw(upgrade_type* pupgrade)
 {
   SDL_Rect dest;
-  if (pupgrade->base.alive)
-    {
       if (pupgrade->base.height < 32)
         {
           /* Rising up... */
@@ -227,7 +217,6 @@ void upgrade_draw(upgrade_type* pupgrade)
                            NO_UPDATE);
             }
         }
-    }
 }
 
 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
@@ -242,7 +231,7 @@ void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
       /* p_c_object is CO_PLAYER, so assign it to pplayer */
       pplayer = (player_type*) p_c_object;
 
-      pupgrade->base.alive = NO;
+      upgrades.erase(static_cast<std::vector<upgrade_type>::iterator>(pupgrade));
 
       /* Affect the player: */
 
index daaba7a..6b5877b 100644 (file)
@@ -19,7 +19,6 @@
 
 typedef struct base_type
   {
-    int alive;
     float x;
     float y;
     float xm;
index 7e7c4e6..6f5da50 100644 (file)
@@ -22,7 +22,6 @@ texture_type img_distro[4];
 
 void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y)
 {
-  pbouncy_distro->base.alive = YES;
   pbouncy_distro->base.x = x;
   pbouncy_distro->base.y = y;
   pbouncy_distro->base.ym = -2;
@@ -30,31 +29,24 @@ void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y)
 
 void bouncy_distro_action(bouncy_distro_type* pbouncy_distro)
 {
-  if (pbouncy_distro->base.alive)
-    {
       pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym * frame_ratio;
 
       pbouncy_distro->base.ym += 0.1 * frame_ratio;
 
       if (pbouncy_distro->base.ym >= 0)
-        pbouncy_distro->base.alive = NO;
-    }
+       bouncy_distros.erase(static_cast<std::vector<bouncy_distro_type>::iterator>(pbouncy_distro));
 }
 
 void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro)
 {
-  if (pbouncy_distro->base.alive)
-    {
       texture_draw(&img_distro[0],
                    pbouncy_distro->base.x - scroll_x,
                    pbouncy_distro->base.y,
                    NO_UPDATE);
-    }
 }
 
 void broken_brick_init(broken_brick_type* pbroken_brick, float x, float y, float xm, float ym)
 {
-  pbroken_brick->base.alive = YES;
   pbroken_brick->base.x = x;
   pbroken_brick->base.y = y;
   pbroken_brick->base.xm = xm;
@@ -65,21 +57,16 @@ void broken_brick_init(broken_brick_type* pbroken_brick, float x, float y, float
 
 void broken_brick_action(broken_brick_type* pbroken_brick)
 {
-  if (pbroken_brick->base.alive)
-    {
       pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio;
       pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio;
 
       if (!timer_check(&pbroken_brick->timer))
-        pbroken_brick->base.alive = NO;
-    }
+        broken_bricks.erase(static_cast<std::vector<broken_brick_type>::iterator>(pbroken_brick));
 }
 
 void broken_brick_draw(broken_brick_type* pbroken_brick)
 {
 SDL_Rect src, dest;
-  if (pbroken_brick->base.alive)
-    {
       src.x = rand() % 16;
       src.y = rand() % 16;
       src.w = 16;
@@ -91,12 +78,10 @@ SDL_Rect src, dest;
       dest.h = 16;
 
       texture_draw_part(&img_brick[0],src.x,src.y,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
-    }
 }
 
 void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y)
 {
-  pbouncy_brick->base.alive = YES;
   pbouncy_brick->base.x = x;
   pbouncy_brick->base.y = y;
   pbouncy_brick->offset = 0;
@@ -107,9 +92,6 @@ void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y)
 void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
 {
 
-  if (pbouncy_brick->base.alive)
-    {
-
       pbouncy_brick->offset = (pbouncy_brick->offset +
                                pbouncy_brick->offset_m * frame_ratio);
 
@@ -122,8 +104,7 @@ void bouncy_brick_action(bouncy_brick_type* pbouncy_brick)
       /* Stop bouncing? */
 
       if (pbouncy_brick->offset >= 0)
-        pbouncy_brick->base.alive = NO;
-    }
+        bouncy_bricks.erase(static_cast<std::vector<bouncy_brick_type>::iterator>(pbouncy_brick));
 }
 
 void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
@@ -131,8 +112,6 @@ void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
   int s;
   SDL_Rect dest;
   
-  if (pbouncy_brick->base.alive)
-    {
       if (pbouncy_brick->base.x >= scroll_x - 32 &&
           pbouncy_brick->base.x <= scroll_x + screen->w)
         {
@@ -156,12 +135,10 @@ void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
                     pbouncy_brick->base.y + pbouncy_brick->offset,
                     pbouncy_brick->shape);
         }
-    }
 }
 
 void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s)
 {
-  pfloating_score->base.alive = YES;
   pfloating_score->base.x = x;
   pfloating_score->base.y = y - 16;
   timer_init(&pfloating_score->timer,YES);
@@ -171,22 +148,16 @@ void floating_score_init(floating_score_type* pfloating_score, float x, float y,
 
 void floating_score_action(floating_score_type* pfloating_score)
 {
-  if (pfloating_score->base.alive)
-    {
       pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio;
 
       if(!timer_check(&pfloating_score->timer))
-        pfloating_score->base.alive = NO;
-    }
+        floating_scores.erase(static_cast<std::vector<floating_score_type>::iterator>(pfloating_score));
 }
 
 void floating_score_draw(floating_score_type* pfloating_score)
 {
-  if (pfloating_score->base.alive)
-    {
       char str[10];
       sprintf(str, "%d", pfloating_score->value);
       text_draw(&gold_text, str, (int)pfloating_score->base.x + 16 - strlen(str) * 8, (int)pfloating_score->base.y, 1, NO_UPDATE);
-    }
 }