X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fspecial%2Fmoving_object.h;h=0103878293caa957eafb2d34450f085e097999b7;hb=8e0bad9f82ccbc811a18edd7ce6c6f69c5bca082;hp=26c7db1c6ca392f79eee28c9e33cec5cedf42718;hpb=9c511ea692d3a2339597211f08f18ea74fad35ec;p=supertux.git diff --git a/lib/special/moving_object.h b/lib/special/moving_object.h index 26c7db1c6..010387829 100644 --- a/lib/special/moving_object.h +++ b/lib/special/moving_object.h @@ -20,42 +20,72 @@ #ifndef SUPERTUX_MOVING_OBJECT_H #define SUPERTUX_MOVING_OBJECT_H -#include "special/base.h" -#include "special/game_object.h" +#include "game_object.h" +#include "collision_hit.h" #include "math/vector.h" -//#include "rectangle.h" - -/** - * Base class for all dynamic/moving game objects. This class contains things - * for handling the bounding boxes and collision feedback. - */ -class MovingObject : public GameObject -{ -public: - MovingObject(); - virtual ~MovingObject(); - - /** this function is called when the object collided with any other object +#include "math/rectangle.h" + +class FlipLevelTransformer; +class Sector; +class CollisionGrid; + +namespace SuperTux + { + + /** + * Base class for all dynamic/moving game objects. This class contains things + * for handling the bounding boxes and collision feedback. */ - virtual void collision(const MovingObject& other_object, - int collision_type) = 0; - - Vector get_pos() const - { return Vector(base.x, base.y); } - - base_type base; - base_type old_base; - -protected: -#if 0 // this will be used in my collision detection rewrite later - /// the current position of the object - Vector pos; - /// the position we want to move until next frame - Vector new_pos; - /// the bounding box relative to the current position - Rectangle bounding_box; -#endif -}; + 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; + + const Vector& get_pos() const + { + return bbox.p1; + } + + /** returns the bounding box of the Object */ + const Rectangle& 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) + { + bbox.set_pos(pos); + } + + protected: + friend class Sector; + friend class CollisionGrid; + + /** The bounding box of the object (as used for collision detection, this + * isn't necessarily the bounding box for graphics) + */ + Rectangle bbox; + /** The movement that will happen till next frame + */ + Vector movement; + }; + +} //namespace SuperTux #endif /*SUPERTUX_MOVING_OBJECT_H*/