nolok dies properly now :)
[supertux.git] / src / object / block.cpp
index ba79474..0dcc549 100644 (file)
@@ -13,6 +13,8 @@
 #include "flower.h"
 #include "oneup.h"
 #include "star.h"
+#include "badguy/badguy.h"
+#include "coin.h"
 
 static const float BOUNCY_BRICK_MAX_OFFSET=8;
 static const float BOUNCY_BRICK_SPEED=90;
@@ -35,23 +37,26 @@ Block::~Block()
 HitResponse
 Block::collision(GameObject& other, const CollisionHit& hitdata)
 {
-  if(bouncing)
-    return FORCE_MOVE;
-  
-  // TODO kill badguys when bumping them...
-  
   Player* player = dynamic_cast<Player*> (&other);
-  if(!player)
-    return ABORT_MOVE;
-
-  // collided from below?
-  if(hitdata.normal.x == 0 && hitdata.normal.y < 0
-      && player->get_movement().y < 0) {
-    printf("hit.\n");
-    hit(*player);
+  if(player) {
+    // collided from below?
+    if(hitdata.normal.x == 0 && hitdata.normal.y < 0) {
+      hit(*player);
+    }
+  }
+
+  if(bouncing) {
+    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
+    if(badguy) {
+      badguy->kill_fall();
+    }
+    Coin* coin = dynamic_cast<Coin*> (&other);
+    if(coin) {
+      coin->collect();
+    }
   }
 
-  return ABORT_MOVE;
+  return FORCE_MOVE;
 }
 
 void
@@ -62,9 +67,9 @@ Block::action(float elapsed_time)
   
   float offset = original_y - get_pos().y;
   if(offset > BOUNCY_BRICK_MAX_OFFSET) {
-    bounce_dir *= -1;
+    bounce_dir = BOUNCY_BRICK_SPEED;
     movement = Vector(0, bounce_dir * elapsed_time);
-  } else if(offset < -EPSILON) {
+  } else if(offset < BOUNCY_BRICK_SPEED * elapsed_time && bounce_dir > 0) {
     movement = Vector(0, offset);
     bounce_dir = 0;
     bouncing = false;
@@ -137,7 +142,7 @@ BonusBlock::hit(Player& player)
       break;
 
     case 3: // star
-      sector->add_object(new Star(get_pos()));
+      sector->add_object(new Star(get_pos() + Vector(0, -32)));
       break;
 
     case 4: // 1up