00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
00018 #define HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
00019
00020 #include <stdint.h>
00021
00022 #include "math/rectf.hpp"
00023 #include "supertux/collision_hit.hpp"
00024 #include "supertux/game_object.hpp"
00025
00026 class Sector;
00027 class CollisionGrid;
00028
00029 enum CollisionGroup {
00031 COLGROUP_DISABLED = 0,
00032
00041 COLGROUP_MOVING_STATIC,
00042
00050 COLGROUP_MOVING,
00051
00057 COLGROUP_MOVING_ONLY_STATIC,
00058
00064 COLGROUP_STATIC,
00065
00070 COLGROUP_TOUCHABLE
00071 };
00072
00076 class MovingObject : public GameObject
00077 {
00078 public:
00079 MovingObject();
00080 virtual ~MovingObject();
00081
00083 virtual void collision_solid(const CollisionHit& hit)
00084 {
00085 (void) hit;
00086 }
00087
00091 virtual bool collides(GameObject& other, const CollisionHit& hit)
00092 {
00093 (void) other;
00094 (void) hit;
00095 return true;
00096 }
00097
00099 virtual HitResponse collision(GameObject& other, const CollisionHit& hit) = 0;
00100
00102 virtual void collision_tile(uint32_t tile_attributes)
00103 {
00104 (void) tile_attributes;
00105 }
00106
00107 const Vector& get_pos() const
00108 {
00109 return bbox.p1;
00110 }
00111
00113 const Rectf& get_bbox() const
00114 {
00115 return bbox;
00116 }
00117
00118 const Vector& get_movement() const
00119 {
00120 return movement;
00121 }
00122
00126 virtual void set_pos(const Vector& pos)
00127 {
00128 dest.move(pos-get_pos());
00129 bbox.set_pos(pos);
00130 }
00131
00135 virtual void set_width(float w)
00136 {
00137 dest.set_width(w);
00138 bbox.set_width(w);
00139 }
00140
00144 virtual void set_size(float w, float h)
00145 {
00146 dest.set_size(w, h);
00147 bbox.set_size(w, h);
00148 }
00149
00150 CollisionGroup get_group() const
00151 {
00152 return group;
00153 }
00154
00155 protected:
00156 friend class Sector;
00157 friend class CollisionGrid;
00158 friend class Platform;
00159
00160 void set_group(CollisionGroup group)
00161 {
00162 this->group = group;
00163 }
00164
00167 Rectf bbox;
00168
00170 Vector movement;
00171
00173 CollisionGroup group;
00174
00175 private:
00181 Rectf dest;
00182 };
00183
00184 #endif
00185
00186