First attempts at making BadGuys cloneable
[supertux.git] / src / badguy / badguy.cpp
index fb2fff9..fa400f4 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;
@@ -37,6 +38,12 @@ BadGuy::BadGuy()
   set_group(COLGROUP_DISABLED);
 }
 
+BadGuy::BadGuy(const BadGuy& other)
+       : MovingObject(other), Serializable(other), countMe(other.countMe), physic(other.physic), activated(other.activated), start_position(other.start_position), dir(other.dir), layer(other.layer), state(other.state), state_timer(other.state_timer)
+{
+  sprite = new Sprite(*other.sprite);
+}
+
 BadGuy::~BadGuy()
 {
   delete sprite;
@@ -145,6 +152,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 +214,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)
 {