Tentative checkin of tuxdev's "Object improvement patch, part 1"
[supertux.git] / src / moving_object.hpp
index 2981829..ae0e1d7 100644 (file)
@@ -63,7 +63,7 @@ enum CollisionGroup {
    * coins
    */
   COLGROUP_TOUCHABLE,
-  
+
   /**
    * Should be used for tilemaps
    */
@@ -77,44 +77,71 @@ enum CollisionGroup {
 class MovingObject : public GameObject
 {
 public:
-  MovingObject();
+  MovingObject(std::string name = "");
+  MovingObject(const lisp::Lisp& lisp);
   virtual ~MovingObject();
-  
-  /** this function is called when the object collided with any other object
-   */
-  virtual HitResponse collision(GameObject& other,
-                                const CollisionHit& hit) = 0;
+
+  /** this function is called when the object collided with something solid */
+  virtual void collision_solid(const CollisionHit& hit)
+  {
+    (void) hit;
+  }
+  /** this function is called when the object collided with any other object */
+  virtual HitResponse collision(GameObject& other, const CollisionHit& hit) = 0;
   /** called when tiles with special attributes have been touched */
   virtual void collision_tile(uint32_t tile_attributes)
   {
     (void) tile_attributes;
   }
-  
+
   const Vector& get_pos() const
   {
     return bbox.p1;
   }
-  
+
   /** returns the bounding box of the Object */
   const Rect& get_bbox() const
   {
     return bbox;
   }
-  
+
   const Vector& get_movement() const
   {
     return movement;
   }
-  
+
   /** places the moving object at a specific position. Be carefull when
    * using this function. There are no collision detection checks performed
    * here so bad things could happen.
    */
   virtual void set_pos(const Vector& pos)
   {
+    dest.move(pos-get_pos());
     bbox.set_pos(pos);
   }
 
+  /**
+   * sets the moving object's bbox to a specific width. Be careful when
+   * using this function. There are no collision detection checks performed
+   * here so bad things could happen.
+   */
+  virtual void set_width(float w)
+  {
+    dest.set_width(w);
+    bbox.set_width(w);
+  }
+
+  /**
+   * sets the moving object's bbox to a specific size. Be careful when
+   * using this function. There are no collision detection checks performed
+   * here so bad things could happen.
+   */
+  /*virtual void set_size(float w, float h)
+  {
+    dest.set_size(w, h);
+    bbox.set_size(w, h);
+  }*/
+
   CollisionGroup get_group() const
   {
     return group;
@@ -124,12 +151,65 @@ public:
   {
     this->group = group;
   }
-  
+
+  // --- BEGIN METHODS TO EXPOSE TO SQUIRREL --- //
+  void set_solid(bool solid)
+  {
+    this->solid = solid;
+  }
+  bool is_solid() const
+  {
+    return solid;
+  }
+  void move(float x, float y)
+  {
+    bbox.move(Vector(x, y));
+  }
+  void set_pos(float x, float y)
+  {
+    set_pos(Vector(x, y));
+  }
+  float get_pos_x() const
+  {
+    return bbox.get_left();
+  }
+  float get_pos_y() const
+  {
+    return bbox.get_top();
+  }
+  void set_size(float w, float h)
+  {
+    dest.set_size(w, h);
+    bbox.set_size(w, h);
+  }
+  float get_width() const
+  {
+    return bbox.get_width();
+  }
+  float get_height() const
+  {
+    return bbox.get_height();
+  }
+  void set_velocity(float x, float y)
+  {
+    movement = Vector(x, y);
+  }
+  float get_velocity_x() const
+  {
+    return movement.x;
+  }
+  float get_velocity_y() const
+  {
+    return movement.y;
+  }
+  // --- END METHODS TO EXPOSE TO SQUIRREL --- //
+
 protected:
+  MovingObject(Rect bbox, CollisionGroup group, bool solid);
   friend class Sector;
   friend class CollisionGrid;
   friend class Platform;
-  
+
   /** The bounding box of the object (as used for collision detection, this
    * isn't necessarily the bounding box for graphics)
    */
@@ -141,8 +221,16 @@ protected:
   CollisionGroup group;
 
 private:
-  // this is only here for internal collision detection use
+  /**
+   * this is only here for internal collision detection use (don't touch this
+   * from outside collision detection code)
+   *
+   * This field holds the currently anticipated destination of the object
+   * during collision detection
+   */
   Rect dest;
+  
+  bool solid; /**< true if this object should be considered when doing collision detection */
 };
 
 #endif