Replaced Ref and RefCounter with std::shared_ptr<>
[supertux.git] / src / badguy / short_fuse.cpp
index ae0c05c..f92ec48 100644 (file)
@@ -15,9 +15,9 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "audio/sound_manager.hpp"
 #include "badguy/bomb.hpp"
 #include "badguy/short_fuse.hpp"
+#include "object/bullet.hpp"
 #include "object/explosion.hpp"
 #include "object/player.hpp"
 #include "sprite/sprite.hpp"
@@ -35,9 +35,6 @@ ShortFuse::ShortFuse(const Reader& reader) :
   walk_speed = 100;
   max_drop_height = -1;
 
-  //Prevent stutter when Tux jumps on Mr Bomb
-  sound_manager->preload("sounds/explosion.wav");
-
   //Check if we need another sprite
   if( !reader.get( "sprite", sprite_name ) ){
     return;
@@ -47,31 +44,23 @@ ShortFuse::ShortFuse(const Reader& reader) :
     return;
   }
   //Replace sprite
-  sprite = sprite_manager->create( sprite_name );
-}
-
-/* ShortFuse created by a dispenser always gets default sprite atm.*/
-ShortFuse::ShortFuse(const Vector& pos, Direction d) :
-  WalkingBadguy(pos, d, "images/creatures/short_fuse/short_fuse.sprite", "left", "right")
-{
-  walk_speed = 80;
-  max_drop_height = 16;
-  sound_manager->preload("sounds/explosion.wav");
+  sprite = SpriteManager::current()->create( sprite_name );
 }
 
 void
-ShortFuse::explode (void)
+ShortFuse::explode()
 {
-  if (!is_valid ())
+  if (!is_valid())
     return;
 
-  Explosion *explosion = new Explosion (get_bbox ().get_middle ());
+  auto explosion = std::make_shared<Explosion>(get_bbox ().get_middle());
 
-  explosion->hurts (false);
-  explosion->pushes (true);
-  Sector::current()->add_object (explosion);
+  explosion->hurts(false);
+  explosion->pushes(true);
+  Sector::current()->add_object(explosion);
 
-  remove_me ();
+  run_dead_script();
+  remove_me();
 }
 
 bool
@@ -97,11 +86,19 @@ ShortFuse::collision_player (Player& player, const CollisionHit&)
   return ABORT_MOVE;
 }
 
+HitResponse
+ShortFuse::collision_bullet (Bullet& bullet, const CollisionHit& )
+{
+  // All bullets cause the unstable short fuse to explode
+  bullet.remove_me();
+  explode();
+  return ABORT_MOVE;
+}
+
 void
 ShortFuse::kill_fall (void)
 {
   explode ();
-  run_dead_script ();
 }
 
 /* vim: set sw=2 sts=2 et : */