Made the stomp cloud to have an independent movement from Tux by making it a GameObject.
authorRicardo Cruz <rick2@aeiou.pt>
Thu, 5 Aug 2004 10:10:19 +0000 (10:10 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Thu, 5 Aug 2004 10:10:19 +0000 (10:10 +0000)
Next time, please don't implement it, unless you do it properly.

SVN-Revision: 1705

src/gameobjs.cpp
src/gameobjs.h
src/player.cpp
src/player.h
src/resources.cpp
src/sector.cpp
src/sector.h

index cb3984d..2bde3cb 100644 (file)
@@ -181,7 +181,7 @@ Trampoline::write(LispWriter& writer)
 void
 Trampoline::draw(DrawingContext& context)
 {
-  img_trampoline[frame]->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
+  img_trampoline[frame]->draw(context, base, LAYER_OBJECTS);
   frame = 0;
 }
 
@@ -336,7 +336,7 @@ FlyingPlatform::write(LispWriter& writer)
 void
 FlyingPlatform::draw(DrawingContext& context)
 {
-  img_flying_platform->draw(context, Vector(base.x, base.y), LAYER_OBJECTS);
+  img_flying_platform->draw(context, base, LAYER_OBJECTS);
 }
 
 void
@@ -413,6 +413,29 @@ FlyingPlatform::collision(void *p_c_object, int c_object, CollisionType type)
   }
 }
 
+Sprite *img_smoke_cloud;
+
+SmokeCloud::SmokeCloud(const Vector& pos)
+  : position(pos)
+{
+  timer.start(250);
+}
+
+void
+SmokeCloud::action(float elapsed_time)
+{
+  position.y -= 2 * elapsed_time;
+
+  if(!timer.check())
+    remove_me();
+}
+
+void
+SmokeCloud::draw(DrawingContext& context)
+{
+  img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1);
+}
+
 void load_object_gfx()
 {
   char sprite_name[16];
@@ -424,4 +447,6 @@ void load_object_gfx()
   }
 
   img_flying_platform = sprite_manager->load("flying_platform");
+
+  img_smoke_cloud = sprite_manager->load("stomp");
 }
index fd89dfd..9112cae 100644 (file)
@@ -162,6 +162,21 @@ public:
   unsigned int frame;
 };
 
+extern Sprite *img_smoke_cloud;
+
+class SmokeCloud : public GameObject
+{
+public:
+  SmokeCloud(const Vector& pos);
+  
+  virtual void action(float elapsed_time);
+  virtual void draw(DrawingContext& context);
+
+private:
+  Timer timer;
+  Vector position;
+};
+
 void load_object_gfx();
 
 #endif 
index 84d2f02..c3170b3 100644 (file)
@@ -40,7 +40,6 @@
 #define TILES_FOR_BUTTJUMP 3
 // animation times (in ms):
 #define SHOOTING_TIME 320
-#define STOMP_TIME 250
 // others stuff:
 #define AUTOSCROLL_DEAD_INTERVAL 300
 
@@ -118,7 +117,6 @@ Player::init()
   can_jump = true;
   butt_jump = false;
   
-  stomp_pos = Vector(0,0);
   frame_main = 0;
   frame_ = 0;
 
@@ -510,12 +508,11 @@ Player::handle_vertical_input()
   // Do butt jump
   if (butt_jump && on_ground() && size == BIG)
   {
-    
+    // Add a smoke cloud
     if (duck) 
-      stomp_pos = Vector(base.x - 32, base.y);
+      Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y));
     else 
-      stomp_pos = Vector(base.x - 32, base.y + 32);    
-    stomp_timer.start(STOMP_TIME);
+      Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y + 32));
     
     butt_jump = false;
 
@@ -774,10 +771,6 @@ Player::draw(DrawingContext& context)
       sprite->grab_left->draw(context, pos, LAYER_OBJECTS + 1);
   }
   
-  // Draw stomp clouds when doing a butt jump
-  if (stomp_timer.check())
-      sprite->stomp->draw(context, stomp_pos, LAYER_OBJECTS + 1);
-
   // Draw blinking star overlay
   if (invincible_timer.started() &&
       (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3))
index 6b1133e..6555527 100644 (file)
@@ -119,7 +119,6 @@ struct PlayerSprite
   Sprite* grab_right;
   Sprite* duck_right;
   Sprite* duck_left;
-  Sprite* stomp;
 };
 
 extern PlayerSprite smalltux;
@@ -163,11 +162,8 @@ public:
   Timer shooting_timer;   // used to show the arm when Tux is shooting
   Timer dying_timer;
   Timer growing_timer;
-  Timer stomp_timer;
   Physic physic;
   
-  Vector stomp_pos;
-
 public:
   Player();
   virtual ~Player();
index 427a950..1664f20 100644 (file)
@@ -143,7 +143,6 @@ void loadshared()
   smalltux.skid_right  = sprite_manager->load("smalltux-skid-right");
   smalltux.grab_left   = sprite_manager->load("smalltux-grab-left");
   smalltux.grab_right  = sprite_manager->load("smalltux-grab-right");
-  smalltux.stomp       = sprite_manager->load("stomp");
 
   largetux.stand_left  = sprite_manager->load("largetux-stand-left");
   largetux.stand_right = sprite_manager->load("largetux-stand-right");
@@ -159,7 +158,6 @@ void loadshared()
   largetux.grab_right  = sprite_manager->load("largetux-grab-right");
   largetux.duck_left   = sprite_manager->load("largetux-duck-left");
   largetux.duck_right  = sprite_manager->load("largetux-duck-right");
-  largetux.stomp       = sprite_manager->load("stomp");
 
   firetux.stand_left  = sprite_manager->load("firetux-stand-left");
   firetux.stand_right = sprite_manager->load("firetux-stand-right");
@@ -175,7 +173,6 @@ void loadshared()
   firetux.grab_right  = sprite_manager->load("firetux-grab-right");
   firetux.duck_left   = sprite_manager->load("firetux-duck-left");
   firetux.duck_right  = sprite_manager->load("firetux-duck-right");
-  firetux.stomp       = sprite_manager->load("stomp");
 
   icetux.stand_left  = sprite_manager->load("icetux-stand-left");
   icetux.stand_right = sprite_manager->load("icetux-stand-right");
@@ -191,8 +188,6 @@ void loadshared()
   icetux.grab_right  = sprite_manager->load("icetux-grab-right");
   icetux.duck_left   = sprite_manager->load("icetux-duck-left");
   icetux.duck_right  = sprite_manager->load("icetux-duck-right");
-  icetux.stomp       = sprite_manager->load("stomp");
-
 
   /* Water: */
   img_water = new Surface(datadir + "/images/shared/water.png", false);
index a108e30..f534f41 100644 (file)
@@ -423,6 +423,12 @@ Sector::update_game_objects()
             std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform),
             flying_platforms.end());
       }
+      SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
+      if(smoke_cloud) {
+        smoke_clouds.erase(
+            std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud),
+            smoke_clouds.end());
+      }
                                                                                 
       delete *i;
       i = gameobjects.erase(i);
@@ -454,6 +460,10 @@ Sector::update_game_objects()
               = dynamic_cast<InteractiveObject*> (*i);
           if(interactive_object)
             interactive_objects.push_back(interactive_object);
+          SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
+          if(smoke_cloud)
+            smoke_clouds.push_back(smoke_cloud);
+
 
           gameobjects.push_back(*i);
   }
@@ -674,6 +684,13 @@ Sector::add_bullet(const Vector& pos, float xm, Direction dir)
   return true;
 }
 
+bool
+Sector::add_smoke_cloud(const Vector& pos)
+{
+  add_object(new SmokeCloud(pos));
+  return true;
+}
+
 /* Break a brick: */
 bool
 Sector::trybreakbrick(const Vector& pos, bool small)
index 5d9822b..1b186ef 100644 (file)
@@ -45,6 +45,7 @@ class FlyingPlatform;
 class TileMap;
 class Upgrade;
 class Bullet;
+class SmokeCloud;
 class BadGuy;
 class Tile;
 
@@ -102,6 +103,7 @@ public:
                                                                                 
   void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
   bool add_bullet(const Vector& pos, float xm, Direction dir);
+  bool add_smoke_cloud(const Vector& pos);
                                                                                 
   /** Try to grab the coin at the given coordinates */
   void trygrabdistro(const Vector& pos, int bounciness);
@@ -154,6 +156,7 @@ private:
 
   std::vector<Upgrade*> upgrades;
   std::vector<Bullet*> bullets;
+  std::vector<SmokeCloud*> smoke_clouds;
 
 public: // ugly
   typedef std::vector<InteractiveObject*> InteractiveObjects;