Badguys are now responsible for killing themselves when hit by a bullet
authorChristoph Sommer <mail@christoph-sommer.de>
Thu, 4 May 2006 19:26:47 +0000 (19:26 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Thu, 4 May 2006 19:26:47 +0000 (19:26 +0000)
SVN-Revision: 3491

src/badguy/badguy.cpp
src/badguy/badguy.hpp
src/object/bullet.cpp

index fb2fff9..0870ead 100644 (file)
@@ -27,6 +27,7 @@
 #include "game_session.hpp"
 #include "log.hpp"
 #include "level.hpp"
+#include "object/bullet.hpp"
 
 static const float SQUISH_TIME = 2;
 static const float X_OFFSCREEN_DISTANCE = 1600;
@@ -145,6 +146,10 @@ BadGuy::collision(GameObject& other, const CollisionHit& hit)
       if(player)
         return collision_player(*player, hit);
 
+      Bullet* bullet = dynamic_cast<Bullet*> (&other);
+      if(bullet)
+        return collision_bullet(*bullet, hit);
+
       return FORCE_MOVE;
     }
     case STATE_SQUISHED:
@@ -203,6 +208,13 @@ BadGuy::collision_squished(Player& )
   return false;
 }
 
+HitResponse
+BadGuy::collision_bullet(Bullet& , const CollisionHit& )
+{
+  kill_fall();
+  return ABORT_MOVE;
+}
+
 void
 BadGuy::kill_squished(Player& player)
 {
index 8cbfb18..182ab6e 100644 (file)
@@ -111,6 +111,10 @@ protected:
    */
   virtual bool collision_squished(Player& player);
 
+  /** Called when the badguy collided with a bullet */
+  virtual HitResponse collision_bullet(Bullet& bullet, 
+      const CollisionHit& hit);
+
   /** called each frame when the badguy is activated. */
   virtual void active_update(float elapsed_time);
   /** called each frame when the badguy is not activated. */
index e878660..40d9a5e 100644 (file)
@@ -105,9 +105,9 @@ Bullet::collision(GameObject& other, const CollisionHit& hit)
     return CONTINUE;
   }
 
+  // hit a Badguy
   BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
   if(badguy) {
-    badguy->kill_fall();
     remove_me();
     return FORCE_MOVE;
   }