- memleak fix and menu fix from MatzeB
[supertux.git] / src / badguy.cpp
index 870ee42..b5012be 100644 (file)
@@ -145,8 +145,8 @@ std::string badguykind_to_string(BadGuyKind kind)
     }
 }
 
-void
-BadGuy::init(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
+BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
+  : removable(false)
 {
   base.x   = x;
   base.y   = y;    
@@ -187,7 +187,7 @@ BadGuy::init(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
     physic.enable_gravity(false);
     set_sprite(img_flame, img_flame);
   } else if(kind == BAD_BOUNCINGSNOWBALL) {
-    physic.set_velocity(-BADGUY_WALK_SPEED, 0);
+    physic.set_velocity(-1.3, 0);
     set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
   } else if(kind == BAD_STALACTITE) {
     physic.enable_gravity(false);
@@ -207,9 +207,9 @@ BadGuy::init(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
   }
 
   // if we're in a solid tile at start correct that now
-  if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(&base)) {
+  if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(base)) {
     printf("Warning: badguy started in wall!.\n");
-    while(collision_object_map(&base))
+    while(collision_object_map(base))
       --base.y;
   }
 }
@@ -276,7 +276,7 @@ BadGuy::action_laptop(float frame_ratio)
           base.x = tux.base.x - 16;
           base.y = tux.base.y + tux.base.height/1.5 - base.height;
         }
-      if(collision_object_map(&base))
+      if(collision_object_map(base))
         {
           base.x = tux.base.x;
           base.y = tux.base.y + tux.base.height/1.5 - base.height;
@@ -408,14 +408,7 @@ BadGuy::fall()
 void
 BadGuy::remove_me()
 {
-  for(std::vector<BadGuy>::iterator i = World::current()->bad_guys.begin(); 
-      i != World::current()->bad_guys.end(); ++i) 
-    {
-      if( & (*i) == this) {
-        World::current()->bad_guys.erase(i);
-        return;
-      }
-    }
+  removable = true;
 }
 
 void
@@ -488,6 +481,15 @@ BadGuy::action_bomb(float frame_ratio)
       set_sprite(img_mrbomb_explosion, img_mrbomb_explosion);
       dying = DYING_NOT; // now the bomb hurts
       timer.start(EXPLODETIME);
+
+      /* play explosion sound */  // FIXME: is the stereo all right? maybe we should use player cordinates...
+      if (base.x < scroll_x + screen->w/2 - 10)
+        play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
+      else if (base.x > scroll_x + screen->w/2 + 10)
+        play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER);
+      else
+        play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER);
+
     } else if(mode == BOMB_EXPLODE) {
       remove_me();
       return;
@@ -863,7 +865,7 @@ BadGuy::squish(Player* player)
     World::current()->add_score(base.x - scroll_x, base.y, 50 * player_status.score_multiplier);
     play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
     player_status.score_multiplier++;
-    remove_me();     
+    remove_me();
     return;
 
   } else if(kind == BAD_BSOD) {
@@ -967,6 +969,7 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
     bump();
     return;
   }
+
   if(type == COLLISION_SQUISH) {
     Player* player = static_cast<Player*>(p_c_object);
     squish(player);