X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmoving_object.hpp;h=b2f3de99536a28c967e6723f3adab543419095c4;hb=4a486d92343d1824b311c234e9321e08f280fe68;hp=79e415bb22bc46e7ca50fbf4403dbe2621421370;hpb=84b2c7183da5b9a4d3edcb47ca60a1d5392b905f;p=supertux.git diff --git a/src/moving_object.hpp b/src/moving_object.hpp index 79e415bb2..b2f3de995 100644 --- a/src/moving_object.hpp +++ b/src/moving_object.hpp @@ -1,7 +1,7 @@ -// $Id: moving_object.h 2295 2005-03-30 01:52:14Z matzebraun $ +// $Id$ // -// SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -30,15 +30,44 @@ class Sector; class CollisionGrid; enum CollisionGroup { + /** Objects in DISABLED group are not tested for collisions */ COLGROUP_DISABLED, + /** + * "default" is moving object. MovingObjects get tested against all other + * objects and against other movingobjects + */ COLGROUP_MOVING, - // moving object but don't collide against other moving objects + /** + * a Moving object, that is not tested against other MovingObjects (or other + * MovingOnlyStatic objects), but is tested against all other objects. + */ COLGROUP_MOVING_ONLY_STATIC, + /** + * Doesn't move and isn't explicitely checked for collisions with other + * objects (but other objects might check with this) + * The difference to COLGROUP_TOUCHABLE is that we can do multiple + * collision response tests in a row which is needed for static object + * that tux walks on. The results for collisions with STATIC objects + * are also sorted by time (so that the first hit gets handled first). + * + * Use this for static obstacles + */ COLGROUP_STATIC, - COLGROUP_MOVINGSTATIC, + /** + * Isn't explicitely checked for collisions with other objects. But other + * objects might check with this object. + * Difference to COLGROUP_STATIC is that collisions with this object are + * only tested once and collision response is typically not handled + * + * Use this for touchable things like spikes/areas or collectibles like + * coins + */ COLGROUP_TOUCHABLE, - - COLGROUP_TILEMAP /* not really used at the moment */ + + /** + * Should be used for tilemaps + */ + COLGROUP_TILEMAP }; /** @@ -50,57 +79,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) */ @@ -110,6 +165,16 @@ protected: Vector movement; /** The collision group */ CollisionGroup group; + +private: + /** + * 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; }; #endif