src/supertux/moving_object.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1