create lisp code on the fly (still no enemies showing up in editor, no idea why....
[supertux.git] / src / object / block.cpp
index c75c990..b3c6fcc 100644 (file)
@@ -13,6 +13,9 @@
 #include "flower.h"
 #include "oneup.h"
 #include "star.h"
+#include "badguy/badguy.h"
+#include "coin.h"
+#include "object_factory.h"
 
 static const float BOUNCY_BRICK_MAX_OFFSET=8;
 static const float BOUNCY_BRICK_SPEED=90;
@@ -35,8 +38,6 @@ Block::~Block()
 HitResponse
 Block::collision(GameObject& other, const CollisionHit& hitdata)
 {
-  // TODO kill badguys when bumping them...
-  
   Player* player = dynamic_cast<Player*> (&other);
   if(player) {
     // collided from below?
@@ -45,6 +46,17 @@ Block::collision(GameObject& other, const CollisionHit& hitdata)
     }
   }
 
+  if(bouncing) {
+    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
+    if(badguy) {
+      badguy->kill_fall();
+    }
+    Coin* coin = dynamic_cast<Coin*> (&other);
+    if(coin) {
+      coin->collect();
+    }
+  }
+
   return FORCE_MOVE;
 }
 
@@ -90,7 +102,13 @@ BonusBlock::BonusBlock(const Vector& pos, int newdata)
 }
 
 void
-BonusBlock::hit(Player& player)
+BonusBlock::hit(Player& )
+{
+  try_open();
+}
+
+void
+BonusBlock::try_open()
 {
   if(sprite->get_action_name() == "empty") {
     SoundManager::get()->play_sound(IDToSound(SND_BRICK));
@@ -98,6 +116,7 @@ BonusBlock::hit(Player& player)
   }
   
   Sector* sector = Sector::current();
+  Player& player = *(sector->player);
   switch(data) {
     case 1: // coin
       Sector::current()->add_object(new BouncyCoin(get_pos()));
@@ -146,6 +165,8 @@ BonusBlock::hit(Player& player)
   sprite->set_action("empty");
 }
 
+//IMPLEMENT_FACTORY(BonusBlock, "bonusblock")
+
 //---------------------------------------------------------------------------
 
 Brick::Brick(const Vector& pos, int data)
@@ -159,13 +180,23 @@ Brick::Brick(const Vector& pos, int data)
 }
 
 void
-Brick::hit(Player& player)
+Brick::hit(Player& )
+{
+  if(sprite->get_action_name() == "empty")
+    return;
+  
+  try_break(true);
+}
+
+void
+Brick::try_break(bool playerhit)
 {
   if(sprite->get_action_name() == "empty")
     return;
   
   SoundManager::get()->play_sound(IDToSound(SND_BRICK));
   Sector* sector = Sector::current();
+  Player& player = *(sector->player);
   if(coin_counter > 0) {
     sector->add_object(new BouncyCoin(get_pos()));
     coin_counter--;
@@ -174,7 +205,7 @@ Brick::hit(Player& player)
       sprite->set_action("empty");
     start_bounce();
   } else if(breakable) {
-    if(player.size == SMALL) {
+    if(playerhit && player.size == SMALL) {
       start_bounce();
       return;
     }
@@ -194,3 +225,4 @@ Brick::hit(Player& player)
   }
 }
 
+//IMPLEMENT_FACTORY(Brick, "brick")