Made buttjump a bit easier to perform
[supertux.git] / src / object / block.cpp
index de4f311..bb309f0 100644 (file)
@@ -32,6 +32,7 @@
 #include "video/drawing_context.hpp"
 #include "lisp/lisp.hpp"
 #include "gameobjs.hpp"
+#include "portable.hpp"
 #include "specialriser.hpp"
 #include "growup.hpp"
 #include "flower.hpp"
@@ -73,15 +74,25 @@ Block::collision(GameObject& other, const CollisionHit& )
     }
   }
 
-  if(bouncing) {
+  // only interact with other objects if...
+  //   1) we are bouncing
+  // and
+  //   2) the object is not portable (either never or not currently)
+  Portable* portable = dynamic_cast<Portable*> (&other);
+  if(bouncing && (portable == 0 || (!portable->is_portable()))) {
+
+    // Badguys get killed
     BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
     if(badguy) {
       badguy->kill_fall();
     }
+
+    // Coins get collected
     Coin* coin = dynamic_cast<Coin*> (&other);
     if(coin) {
       coin->collect();
     }
+
   }
 
   return SOLID;
@@ -223,6 +234,13 @@ BonusBlock::collision(GameObject& other, const CollisionHit& hit){
         try_open();
       }
     }
+    Portable* portable = dynamic_cast<Portable*> (&other);
+    if(portable) {
+      MovingObject* moving = dynamic_cast<MovingObject*> (&other);
+      if(moving->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) {
+        try_open();
+      }
+    }
     return Block::collision(other, hit);
 }
 
@@ -325,47 +343,60 @@ Brick::Brick(const Vector& pos, int data)
 }
 
 void
-Brick::hit(Player& )
+Brick::hit(Player& player)
 {
   if(sprite->get_action() == "empty")
     return;
 
-  try_break(true);
+  try_break(&player);
 }
 
 HitResponse
 Brick::collision(GameObject& other, const CollisionHit& hit){
+
+    Player* player = dynamic_cast<Player*> (&other);
+    if (player) {
+      if (player->does_buttjump) try_break();
+    }
+
     BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
     if(badguy) {
       // hit contains no information for collisions with blocks.
       // Badguy's bottom has to be below the top of the brick
       // +7 is required to slide over one tile gaps.
       if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > get_bbox().get_top() + 7.0 ) ){
-        try_break(false);
+        try_break();
+      }
+    }
+    Portable* portable = dynamic_cast<Portable*> (&other);
+    if(portable) {
+      MovingObject* moving = dynamic_cast<MovingObject*> (&other);
+      if(moving->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) {
+        try_break();
       }
     }
    return Block::collision(other, hit);
 }
 
 void
-Brick::try_break(bool playerhit)
+Brick::try_break(Player* player)
 {
   if(sprite->get_action() == "empty")
     return;
 
   sound_manager->play("sounds/brick.wav");
   Sector* sector = Sector::current();
-  Player& player = *(sector->player);
+  Player& player_one = *(sector->player);
   if(coin_counter > 0) {
     sector->add_object(new BouncyCoin(get_pos()));
     coin_counter--;
-    player.get_status()->add_coins(1);
+    player_one.get_status()->add_coins(1);
     if(coin_counter == 0)
       sprite->set_action("empty");
     start_bounce();
   } else if(breakable) {
-    if(playerhit){
-      if(player.is_big()){
+    if(player){
+      if(player->is_big()){
         start_break();
         return;
       } else {