Replaced Ref and RefCounter with std::shared_ptr<>
[supertux.git] / src / object / block.cpp
index 420a4b1..1e115d9 100644 (file)
 
 #include "audio/sound_manager.hpp"
 #include "badguy/badguy.hpp"
-#include "lisp/list_iterator.hpp"
 #include "object/broken_brick.hpp"
 #include "object/coin.hpp"
 #include "object/flower.hpp"
-#include "object/bouncy_coin.hpp"
 #include "object/growup.hpp"
-#include "object/oneup.hpp"
 #include "object/player.hpp"
 #include "object/portable.hpp"
-#include "object/specialriser.hpp"
-#include "object/star.hpp"
-#include "sprite/sprite_manager.hpp"
 #include "supertux/constants.hpp"
-#include "supertux/level.hpp"
-#include "supertux/object_factory.hpp"
 #include "supertux/sector.hpp"
 
 static const float BOUNCY_BRICK_MAX_OFFSET = 8;
 static const float BOUNCY_BRICK_SPEED = 90;
-static const float EPSILON = .0001f;
 static const float BUMP_ROTATION_ANGLE = 10;
 
-Block::Block(std::auto_ptr<Sprite> newsprite) :
-  sprite(newsprite), 
-  bouncing(false), 
-  breaking(false), 
-  bounce_dir(0), 
-  bounce_offset(0), 
+Block::Block(SpritePtr newsprite) :
+  sprite(newsprite),
+  bouncing(false),
+  breaking(false),
+  bounce_dir(0),
+  bounce_offset(0),
   original_y(-1)
 {
   bbox.set_size(32, 32.1f);
   set_group(COLGROUP_STATIC);
-  sound_manager->preload("sounds/upgrade.wav");
-  sound_manager->preload("sounds/brick.wav");
+  SoundManager::current()->preload("sounds/upgrade.wav");
+  SoundManager::current()->preload("sounds/brick.wav");
 }
 
 Block::~Block()
@@ -89,7 +80,7 @@ Block::collision(GameObject& other, const CollisionHit& )
     if(coin) {
       coin->collect();
     }
-    
+
     //Eggs get jumped
     GrowUp* growup = dynamic_cast<GrowUp*> (&other);
     if(growup) {
@@ -98,7 +89,7 @@ Block::collision(GameObject& other, const CollisionHit& )
 
   }
 
-  return SOLID;
+  return FORCE_MOVE;
 }
 
 void
@@ -155,4 +146,22 @@ Block::start_break(GameObject* hitter)
   breaking = true;
 }
 
+void
+Block::break_me()
+{
+  Sector* sector = Sector::current();
+  sector->add_object(
+    std::make_shared<BrokenBrick>(sprite->clone(), get_pos(), Vector(-100, -400)));
+  sector->add_object(
+    std::make_shared<BrokenBrick>(sprite->clone(), get_pos() + Vector(0, 16),
+                                  Vector(-150, -300)));
+  sector->add_object(
+    std::make_shared<BrokenBrick>(sprite->clone(), get_pos() + Vector(16, 0),
+                                  Vector(100, -400)));
+  sector->add_object(
+    std::make_shared<BrokenBrick>(sprite->clone(), get_pos() + Vector(16, 16),
+                                  Vector(150, -300)));
+  remove_me();
+}
+
 /* EOF */