First attempts at making BadGuys cloneable
authorChristoph Sommer <mail@christoph-sommer.de>
Thu, 11 May 2006 19:35:16 +0000 (19:35 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Thu, 11 May 2006 19:35:16 +0000 (19:35 +0000)
SVN-Revision: 3505

38 files changed:
src/badguy/angrystone.hpp
src/badguy/badguy.cpp
src/badguy/badguy.hpp
src/badguy/bomb.hpp
src/badguy/bouncing_snowball.hpp
src/badguy/dart.cpp
src/badguy/dart.hpp
src/badguy/darttrap.hpp
src/badguy/dispenser.hpp
src/badguy/fish.hpp
src/badguy/flame.cpp
src/badguy/flame.hpp
src/badguy/flyingsnowball.hpp
src/badguy/igel.hpp
src/badguy/jumpy.hpp
src/badguy/kugelblitz.hpp
src/badguy/mrbomb.hpp
src/badguy/mriceblock.hpp
src/badguy/mrrocket.hpp
src/badguy/mrtree.hpp
src/badguy/nolok_01.hpp
src/badguy/plant.hpp
src/badguy/poisonivy.hpp
src/badguy/rocketexplosion.hpp
src/badguy/skullyhop.hpp
src/badguy/snail.hpp
src/badguy/snowball.hpp
src/badguy/spidermite.hpp
src/badguy/spiky.hpp
src/badguy/sspiky.hpp
src/badguy/stalactite.hpp
src/badguy/totem.cpp
src/badguy/totem.hpp
src/badguy/willowisp.cpp
src/badguy/willowisp.hpp
src/badguy/yeti.hpp
src/badguy/yeti_stalactite.hpp
src/badguy/zeekling.hpp

index b658ca8..0b7dbf7 100644 (file)
@@ -35,6 +35,8 @@ public:
   void active_update(float elapsed_time);
   void kill_fall();
 
+  virtual AngryStone* clone() const { return new AngryStone(*this); }
+
 protected:
   Vector attackDirection;  /**< 1-normalized vector of current attack direction */
   Vector oldWallDirection; /**< if wall was hit during last attack: 1-normalized vector of last attack direction, (0,0) otherwise */
index 0870ead..fa400f4 100644 (file)
@@ -38,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;
index 182ab6e..e9f6833 100644 (file)
@@ -44,6 +44,7 @@ class BadGuy : public MovingObject, public Serializable
 {
 public:
   BadGuy();
+  BadGuy(const BadGuy& badguy);
   ~BadGuy();
 
   /** Called when the badguy is drawn. The default implementation simply draws
@@ -87,6 +88,8 @@ public:
    * during runtime. */
   bool countMe;
 
+  virtual BadGuy* clone() const = 0;
+
 protected:
   enum State {
     STATE_INIT,
index b2da78b..abd8b9d 100644 (file)
@@ -35,6 +35,8 @@ public:
   void kill_fall();
   void explode();
 
+  virtual Bomb* clone() const { return new Bomb(*this); }
+
 private:
   enum State {
     STATE_TICKING,
index ba6c7b2..a16ed22 100644 (file)
@@ -33,6 +33,8 @@ public:
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 
+  virtual BouncingSnowball* clone() const { return new BouncingSnowball(*this); }
+
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
index 1c6ab0d..8e508d9 100644 (file)
@@ -46,11 +46,27 @@ Dart::Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent = 0) : se
   countMe = false;
 }
 
+Dart::Dart(const Dart& other)
+       : BadGuy(other), set_direction(other.set_direction), initial_direction(other.initial_direction), parent(other.parent)
+{
+  soundSource = sound_manager->create_sound_source("sounds/flame.wav");
+}
+
 Dart::~Dart()
 {
   delete soundSource;
 }
 
+bool 
+Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
+{
+  if (from_object == parent) {
+    parent = dynamic_cast<Dart*>(to_object);
+    return true;
+  }
+  return false;
+}
+
 void
 Dart::write(lisp::Writer& writer)
 {
index c816e92..aaebdc2 100644 (file)
@@ -31,6 +31,7 @@ class Dart : public BadGuy
 public:
   Dart(const lisp::Lisp& reader);
   Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent);
+  Dart(const Dart& dart);
   ~Dart();
 
   void activate();
@@ -43,6 +44,10 @@ public:
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
   HitResponse collision_player(Player& player, const CollisionHit& hit);
 
+  virtual Dart* clone() const { return new Dart(*this); }
+
+  virtual bool updatePointers(const GameObject* from_object, GameObject* to_object);
+
 protected:
   bool set_direction;
   Direction initial_direction;
index d3598b8..461e852 100644 (file)
@@ -36,6 +36,8 @@ public:
   void active_update(float elapsed_time);
   HitResponse collision_player(Player& player, const CollisionHit& hit);
 
+  virtual DartTrap* clone() const { return new DartTrap(*this); }
+
 protected:
   enum State {
     IDLE, LOADING
index fc1a424..f79e8e6 100644 (file)
@@ -32,6 +32,8 @@ public:
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
 
+  virtual Dispenser* clone() const { return new Dispenser(*this); }
+
 protected:
   bool collision_squished(Player& player);
   void launch_badguy();
index 173eb4c..8126783 100644 (file)
@@ -37,6 +37,8 @@ public:
   void write(lisp::Writer& );
   void active_update(float);
 
+  virtual Fish* clone() const { return new Fish(*this); }
+
 private:
   HitResponse hit(const CollisionHit& );
   void start_waiting();
index c88e118..4bdafb6 100644 (file)
@@ -37,8 +37,12 @@ Flame::Flame(const lisp::Lisp& reader)
   layer = LAYER_FLOATINGOBJECTS;
 }
 
-Flame::~Flame()
+Flame::Flame(const Flame& other)
+  : BadGuy(other), angle(other.angle), radius(other.radius), speed(other.speed)
 {
+  if (sound_manager->is_sound_enabled()) {
+    source.reset(sound_manager->create_sound_source("sounds/flame.wav"));
+  }
 }
 
 void
index b437efd..303c698 100644 (file)
@@ -25,7 +25,7 @@ class Flame : public BadGuy
 {
 public:
   Flame(const lisp::Lisp& reader);
-  ~Flame();
+  Flame(const Flame& flame);
 
   void activate();
   void deactivate();
@@ -34,6 +34,8 @@ public:
   void active_update(float elapsed_time);
   void kill_fall();
 
+  virtual Flame* clone() const { return new Flame(*this); }
+
 private:
   float angle;
   float radius;
index c9fa3fc..3bac639 100644 (file)
@@ -32,6 +32,9 @@ public:
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+
+  virtual FlyingSnowBall* clone() const { return new FlyingSnowBall(*this); }
+
 protected:
   enum FlyingSnowballMode {
     FLY_UP,
index 14b8ee5..be0a7b3 100644 (file)
@@ -40,6 +40,8 @@ public:
 
   void active_update(float elapsed_time);
 
+  virtual Igel* clone() const { return new Igel(*this); }
+
 protected:
   bool collision_squished(Player& player);
   void be_normal(); /**< switch to state STATE_NORMAL */
index 1ca2aa4..9304a42 100644 (file)
@@ -33,6 +33,8 @@ public:
   void write(lisp::Writer& writer);
   void active_update(float);
 
+  virtual Jumpy* clone() const { return new Jumpy(*this); }
+
 private:
   HitResponse hit(const CollisionHit& hit);
   Vector pos_groundhit;
index e5ffd63..a9c64ba 100644 (file)
@@ -39,6 +39,8 @@ public:
   void kill_fall();
   void explode();
 
+  virtual Kugelblitz* clone() const { return new Kugelblitz(*this); }
+
 private:
   void try_activate();
   HitResponse hit(const CollisionHit& hit);
index 92af127..86c4fa6 100644 (file)
@@ -35,6 +35,8 @@ public:
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
   void kill_fall();
 
+  virtual MrBomb* clone() const { return new MrBomb(*this); }
+
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
index 7ded21a..d3ad9db 100644 (file)
@@ -41,6 +41,8 @@ public:
   void grab(MovingObject& object, const Vector& pos, Direction dir);
   void ungrab(MovingObject& object, Direction dir);
 
+  virtual MrIceBlock* clone() const { return new MrIceBlock(*this); }
+
 protected:
   bool collision_squished(Player& player);
 
index 8550a42..25500ec 100644 (file)
@@ -35,6 +35,8 @@ public:
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
 
+  virtual MrRocket* clone() const { return new MrRocket(*this); }
+
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
index db3d019..652a00e 100644 (file)
@@ -33,6 +33,8 @@ public:
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 
+  virtual MrTree* clone() const { return new MrTree(*this); }
+
 protected:
   enum MyState {
     STATE_BIG, STATE_INVINCIBLE, STATE_NORMAL
index 45a93bd..2a0cdf0 100644 (file)
@@ -34,7 +34,9 @@ public:
   void active_update(float elapsed_time);
   void kill_fall();
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
-  
+  virtual Nolok_01* clone() const { return new Nolok_01(*this); }
+
 protected:
   bool collision_squished(Player& player);
   Timer action_timer;
index 49755fd..ab0dfd5 100644 (file)
@@ -33,6 +33,8 @@ public:
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
   void active_update(float elapsed_time);
 
+  virtual Plant* clone() const { return new Plant(*this); }
+
 protected:
   Timer timer;
 
index 33d7e2c..0005eaa 100644 (file)
@@ -32,7 +32,9 @@ public:
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
-  
+  virtual PoisonIvy* clone() const { return new PoisonIvy(*this); }
+
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
index 63ca12a..c76a6b8 100644 (file)
@@ -35,6 +35,8 @@ public:
   void kill_fall();
   void explode();
 
+  virtual RocketExplosion* clone() const { return new RocketExplosion(*this); }
+
 private:
   Timer timer;
 };
index 6e86119..13c7d06 100644 (file)
@@ -39,6 +39,8 @@ public:
   bool collision_squished(Player& player);
   void active_update(float elapsed_time);
 
+  virtual SkullyHop* clone() const { return new SkullyHop(*this); }
+
 protected:
   enum SkullyHopState {
     STANDING,
index 76252ca..7aff914 100644 (file)
@@ -38,6 +38,8 @@ public:
 
   void active_update(float elapsed_time);
 
+  virtual Snail* clone() const { return new Snail(*this); }
+
 protected:
   bool collision_squished(Player& player);
   void be_normal(); /**< switch to state STATE_NORMAL */
index ce642fb..dfd0e8e 100644 (file)
@@ -32,7 +32,9 @@ public:
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
-  
+  virtual SnowBall* clone() const { return new SnowBall(*this); }
+
 protected:
   bool collision_squished(Player& player);
   bool set_direction;
index 113a70c..048831c 100644 (file)
@@ -32,6 +32,9 @@ public:
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+
+  virtual SpiderMite* clone() const { return new SpiderMite(*this); }
+
 protected:
   enum SpiderMiteMode {
     FLY_UP,
index 8eed442..f4cbe69 100644 (file)
@@ -32,6 +32,9 @@ public:
   void active_update(float elapsed_time);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+
+  virtual Spiky* clone() const { return new Spiky(*this); }
+
 };
 
 #endif
index 532e06e..bb77419 100644 (file)
@@ -33,6 +33,8 @@ public:
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
   void active_update(float elapsed_time);
 
+  virtual SSpiky* clone() const { return new SSpiky(*this); }
+
 protected:
   Timer timer;
 
index bd58d1b..9619f61 100644 (file)
@@ -36,6 +36,8 @@ public:
   void draw(DrawingContext& context);
   void deactivate();
 
+  virtual Stalactite* clone() const { return new Stalactite(*this); }
+
 protected:
   Timer timer;
 
index 88620f9..7d2b932 100644 (file)
@@ -38,12 +38,31 @@ Totem::Totem(const lisp::Lisp& reader)
   bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
 }
 
+Totem::Totem(const Totem& other)
+       : BadGuy(other), carrying(other.carrying), carried_by(other.carried_by)
+{
+}
+
 Totem::~Totem() 
 {
   if (carrying) carrying->jump_off();
   if (carried_by) jump_off();
 }
 
+bool 
+Totem::updatePointers(const GameObject* from_object, GameObject* to_object)
+{
+  if (from_object == carrying) {
+    carrying = dynamic_cast<Totem*>(to_object);
+    return true;
+  }
+  if (from_object == carried_by) {
+    carried_by = dynamic_cast<Totem*>(to_object);
+    return true;
+  }
+  return false;
+}
+
 void
 Totem::write(lisp::Writer& writer)
 {
index f64e098..8742025 100644 (file)
@@ -30,6 +30,7 @@ class Totem : public BadGuy
 {
 public:
   Totem(const lisp::Lisp& reader);
+  Totem(const Totem& totem);
   ~Totem();
 
   void activate();
@@ -38,6 +39,9 @@ public:
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 
+  virtual Totem* clone() const { return new Totem(*this); }
+  virtual bool updatePointers(const GameObject* from_object, GameObject* to_object);
+
 protected:
   Totem* carrying; /**< Totem we are currently carrying (or 0) */
   Totem* carried_by; /**< Totem by which we are currently carried (or 0) */
index d9c6a63..1a4969b 100644 (file)
@@ -41,6 +41,12 @@ WillOWisp::WillOWisp(const lisp::Lisp& reader)
   layer = LAYER_FLOATINGOBJECTS;
 }
 
+WillOWisp::WillOWisp(const WillOWisp& other) 
+       : BadGuy(other), mystate(other.mystate), target_sector(other.target_sector), target_spawnpoint(other.target_spawnpoint)
+{
+  soundSource = sound_manager->create_sound_source("sounds/willowisp.wav");
+}
+
 WillOWisp::~WillOWisp()
 {
   delete soundSource;
index e216716..cfbcb19 100644 (file)
@@ -27,6 +27,7 @@ class WillOWisp : public BadGuy
 {
 public:
   WillOWisp(const lisp::Lisp& reader);
+  WillOWisp(const WillOWisp& willowisp);
   ~WillOWisp();
 
   void activate();
@@ -38,6 +39,8 @@ public:
 
   virtual void draw(DrawingContext& context);
 
+  virtual WillOWisp* clone() const { return new WillOWisp(*this); }
+
 protected:
   HitResponse collision_player(Player& player, const CollisionHit& hit);
 
index b9d4f45..30a6744 100644 (file)
@@ -38,6 +38,8 @@ public:
   void kill_squished(Player& player);
   void kill_fall();
 
+  virtual Yeti* clone() const { return new Yeti(*this); }
+
 private:
   void run();
   void jump_up();
index f0e5d23..40ead0d 100644 (file)
@@ -33,6 +33,8 @@ public:
   void active_update(float elapsed_time);
   void start_shaking();
   bool is_hanging();
+
+  virtual YetiStalactite* clone() const { return new YetiStalactite(*this); }
 };
 
 #endif
index 1fee377..ab88a9a 100644 (file)
@@ -35,6 +35,8 @@ public:
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   void active_update(float elapsed_time);
 
+  virtual Zeekling* clone() const { return new Zeekling(*this); }
+
 protected:
   bool collision_squished(Player& player);
   bool set_direction;