Bonusblock and Bricks now break themself when hit by MrIceblock or Snail.
authorWolfgang Becker <uafr@gmx.de>
Wed, 12 Jul 2006 23:04:09 +0000 (23:04 +0000)
committerWolfgang Becker <uafr@gmx.de>
Wed, 12 Jul 2006 23:04:09 +0000 (23:04 +0000)
SVN-Revision: 3993

src/badguy/badguy.hpp
src/badguy/mriceblock.cpp
src/badguy/mriceblock.hpp
src/badguy/snail.cpp
src/badguy/snail.hpp
src/object/block.cpp
src/object/block.hpp

index 44613e4..5152139 100644 (file)
@@ -72,6 +72,14 @@ public:
    */
   virtual void save(lisp::Writer& writer);
 
+  /**
+   * True if this badguy can break bricks or open bonusblocks in his current form.
+   */
+  virtual bool can_break()
+  {
+    return false;
+  }
+
   Vector get_start_position() const
   {
     return start_position;
index 8b3a995..472aa17 100644 (file)
@@ -81,6 +81,11 @@ MrIceBlock::active_update(float elapsed_time)
   BadGuy::active_update(elapsed_time);
 }
 
+bool
+MrIceBlock::can_break(){
+    return ice_state == ICESTATE_KICKED;
+}
+
 void
 MrIceBlock::collision_solid(const CollisionHit& hit)
 {
@@ -97,17 +102,6 @@ MrIceBlock::collision_solid(const CollisionHit& hit)
       WalkingBadguy::collision_solid(hit);
       break;
     case ICESTATE_KICKED: {
-#if 0
-      // TODO move these into bonusblock class
-      BonusBlock* bonusblock = dynamic_cast<BonusBlock*> (&object);
-      if(bonusblock) {
-        bonusblock->try_open();
-      }
-      Brick* brick = dynamic_cast<Brick*> (&object);
-      if(brick) {
-        brick->try_break();
-      }
-#endif
       if(hit.right && dir == RIGHT) {
         dir = LEFT;
         sound_manager->play("sounds/iceblock_bump.wav", get_pos());
index 4f95bd9..98c4225 100644 (file)
@@ -40,6 +40,7 @@ public:
   
   void grab(MovingObject& object, const Vector& pos, Direction dir);
   void ungrab(MovingObject& object, Direction dir);
+  bool can_break();
 
   virtual MrIceBlock* clone() const { return new MrIceBlock(*this); }
 
index f54573f..cb34a8f 100644 (file)
@@ -99,6 +99,10 @@ Snail::be_kicked()
   kicked_delay_timer.start(0.05);
 }
 
+bool
+Snail::can_break(){
+    return state == STATE_KICKED;
+}
 
 void
 Snail::active_update(float elapsed_time)
@@ -168,18 +172,6 @@ Snail::collision_solid(const CollisionHit& hit)
       if(hit.left || hit.right) {
        sound_manager->play("sounds/iceblock_bump.wav", get_pos());
 
-#if 0
-       // TODO move this into BonusBlock code
-       // open bonusblocks, crash bricks
-       BonusBlock* bonusblock = dynamic_cast<BonusBlock*> (&object);
-       if(bonusblock) {
-         bonusblock->try_open();
-       }
-       Brick* brick = dynamic_cast<Brick*> (&object);
-       if(brick) {
-         brick->try_break();
-       }
-#endif
        if( ( dir == LEFT && hit.left ) || ( dir == RIGHT && hit.right) ){
          dir = (dir == LEFT) ? RIGHT : LEFT;
          sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
index 83f4a10..7427f02 100644 (file)
@@ -35,6 +35,7 @@ public:
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+  bool can_break();
 
   void active_update(float elapsed_time);
 
index 95520d6..ce727af 100644 (file)
@@ -202,6 +202,18 @@ BonusBlock::hit(Player& )
   try_open();
 }
 
+HitResponse
+BonusBlock::collision(GameObject& other, const CollisionHit& hit){
+    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
+    if(badguy) {
+      // if( badguy->can_break() && (hit.left||hit.right||hit.bottom) ){ //TODO: find out why hit contains no information and fix it
+      if( badguy->can_break() && ( badguy->get_pos().y > get_pos().y ) ){
+        try_open();
+      }
+    }
+    return Block::collision(other, hit);
+}
+
 void
 BonusBlock::try_open()
 {
@@ -286,6 +298,18 @@ Brick::hit(Player& )
   try_break(true);
 }
 
+HitResponse
+Brick::collision(GameObject& other, const CollisionHit& hit){
+    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
+    if(badguy) {
+      // if( badguy->can_break() && (hit.left||hit.right||hit.bottom) ){ //TODO: find out why hit contains no information and fix it
+      if( badguy->can_break() && ( badguy->get_pos().y > get_pos().y ) ){
+        try_break(false);
+      }
+    }
+   return Block::collision(other, hit);
+}
+
 void
 Brick::try_break(bool playerhit)
 {
index 07b37cb..462e8ff 100644 (file)
@@ -56,6 +56,7 @@ public:
   BonusBlock(const Vector& pos, int data);
   BonusBlock(const lisp::Lisp& lisp);
   virtual ~BonusBlock();
+  HitResponse collision(GameObject& other, const CollisionHit& hit);
 
   void try_open();
 
@@ -82,6 +83,7 @@ public:
   Brick(const Vector& pos, int data);
 
   void try_break(bool playerhit = false);
+  HitResponse collision(GameObject& other, const CollisionHit& hit);
 
 protected:
   virtual void hit(Player& player);