X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmoving_object.hpp;h=31f47ad239eb4a981e33da181aaa383112d216ff;hb=ad961cb86ef28feed73e1f524fda692ed58d4e5e;hp=63950ccd5bd3e635bdcac4a43f30a2059b8d30ae;hpb=2a354dd7c6c0b83f9f0c65abccb7c6ce020ffc01;p=supertux.git diff --git a/src/moving_object.hpp b/src/moving_object.hpp index 63950ccd5..31f47ad23 100644 --- a/src/moving_object.hpp +++ b/src/moving_object.hpp @@ -31,7 +31,7 @@ class CollisionGrid; enum CollisionGroup { /** Objects in DISABLED group are not tested for collisions */ - COLGROUP_DISABLED, + COLGROUP_DISABLED = 0, /** * "default" is moving object. MovingObjects get tested against all other * objects and against other movingobjects @@ -42,6 +42,8 @@ enum CollisionGroup { * MovingOnlyStatic objects), but is tested against all other objects. */ COLGROUP_MOVING_ONLY_STATIC, + /** TODO write docu :-/ */ + COLGROUP_MOVING_STATIC, /** * Doesn't move and isn't explicitely checked for collisions with other * objects (but other objects might check with this) @@ -63,7 +65,7 @@ enum CollisionGroup { * coins */ COLGROUP_TOUCHABLE, - + /** * Should be used for tilemaps */ @@ -79,57 +81,83 @@ class MovingObject : public GameObject public: MovingObject(); 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); } - CollisionGroup get_group() const + /** + * 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) { - return group; + dest.set_width(w); + bbox.set_width(w); } - void set_group(CollisionGroup group) + /** + * 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) { - this->group = group; + dest.set_size(w, h); + bbox.set_size(w, h); + } + + CollisionGroup get_group() const + { + return group; } - + protected: friend class Sector; friend class CollisionGrid; friend class Platform; - + + void set_group(CollisionGroup group) + { + this->group = group; + } + /** The bounding box of the object (as used for collision detection, this * isn't necessarily the bounding box for graphics) */