79e415bb22bc46e7ca50fbf4403dbe2621421370
[supertux.git] / src / moving_object.hpp
1 //  $Id: moving_object.h 2295 2005-03-30 01:52:14Z matzebraun $
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 #ifndef SUPERTUX_MOVING_OBJECT_H
20 #define SUPERTUX_MOVING_OBJECT_H
21
22 #include <stdint.h>
23
24 #include "game_object.hpp"
25 #include "collision_hit.hpp"
26 #include "math/vector.hpp"
27 #include "math/rect.hpp"
28
29 class Sector;
30 class CollisionGrid;
31
32 enum CollisionGroup {
33   COLGROUP_DISABLED,
34   COLGROUP_MOVING,
35   // moving object but don't collide against other moving objects
36   COLGROUP_MOVING_ONLY_STATIC,
37   COLGROUP_STATIC,
38   COLGROUP_MOVINGSTATIC,
39   COLGROUP_TOUCHABLE,
40   
41   COLGROUP_TILEMAP /* not really used at the moment */
42 };
43
44 /**
45  * Base class for all dynamic/moving game objects. This class contains things
46  * for handling the bounding boxes and collision feedback.
47  */
48 class MovingObject : public GameObject
49 {
50 public:
51   MovingObject();
52   virtual ~MovingObject();
53   
54   /** this function is called when the object collided with any other object
55    */
56   virtual HitResponse collision(GameObject& other,
57                                 const CollisionHit& hit) = 0;
58   /** called when tiles with special attributes have been touched */
59   virtual void collision_tile(uint32_t tile_attributes)
60   {
61     (void) tile_attributes;
62   }
63   
64   const Vector& get_pos() const
65   {
66     return bbox.p1;
67   }
68   
69   /** returns the bounding box of the Object */
70   const Rect& get_bbox() const
71   {
72     return bbox;
73   }
74   
75   const Vector& get_movement() const
76   {
77     return movement;
78   }
79   
80   /** places the moving object at a specific position. Be carefull when
81    * using this function. There are no collision detection checks performed
82    * here so bad things could happen.
83    */
84   virtual void set_pos(const Vector& pos)
85   {
86     bbox.set_pos(pos);
87   }
88
89   CollisionGroup get_group() const
90   {
91     return group;
92   }
93
94   void set_group(CollisionGroup group)
95   {
96     this->group = group;
97   }
98   
99 protected:
100   friend class Sector;
101   friend class CollisionGrid;
102   friend class Platform;
103   
104   /** The bounding box of the object (as used for collision detection, this
105    * isn't necessarily the bounding box for graphics)
106    */
107   Rect bbox;
108   /** The movement that will happen till next frame
109    */
110   Vector movement;
111   /** The collision group */
112   CollisionGroup group;
113 };
114
115 #endif