2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
22 #include "math/rectf.hpp"
23 #include "supertux/collision_hit.hpp"
24 #include "supertux/game_object.hpp"
30 /** Objects in DISABLED group are not tested for collisions */
31 COLGROUP_DISABLED = 0,
37 - other moving objects
38 and it counts as an obstacle during static collision phase.
40 Use for kinematic moving objects like platforms and rocks. */
41 COLGROUP_MOVING_STATIC,
47 - other moving objects
49 Use for ordinary objects. */
56 Use for interactive particles and decoration. */
57 COLGROUP_MOVING_ONLY_STATIC,
61 and it counts as an obstacle during static collision phase.
63 Use for static obstacles that Tux walks on. */
69 Use for triggers like spikes/areas or collectibles like coins. */
73 /** Base class for all dynamic/moving game objects. This class
74 contains things for handling the bounding boxes and collision
76 class MovingObject : public GameObject
80 virtual ~MovingObject();
82 /** this function is called when the object collided with something solid */
83 virtual void collision_solid(const CollisionHit& hit)
88 /** when 2 objects collided, we will first call the
89 pre_collision_check functions of both objects that can decide on
90 how to react to the collision. */
91 virtual bool collides(GameObject& other, const CollisionHit& hit)
98 /** this function is called when the object collided with any other object */
99 virtual HitResponse collision(GameObject& other, const CollisionHit& hit) = 0;
101 /** called when tiles with special attributes have been touched */
102 virtual void collision_tile(uint32_t tile_attributes)
104 (void) tile_attributes;
107 const Vector& get_pos() const
112 /** returns the bounding box of the Object */
113 const Rectf& get_bbox() const
118 const Vector& get_movement() const
123 /** places the moving object at a specific position. Be careful when
124 using this function. There are no collision detection checks
125 performed here so bad things could happen. */
126 virtual void set_pos(const Vector& pos)
128 dest.move(pos-get_pos());
132 /** sets the moving object's bbox to a specific width. Be careful
133 when using this function. There are no collision detection
134 checks performed here so bad things could happen. */
135 virtual void set_width(float w)
141 /** sets the moving object's bbox to a specific size. Be careful
142 when using this function. There are no collision detection
143 checks performed here so bad things could happen. */
144 virtual void set_size(float w, float h)
150 CollisionGroup get_group() const
157 friend class CollisionGrid;
158 friend class Platform;
160 void set_group(CollisionGroup group_)
162 this->group = group_;
165 /** The bounding box of the object (as used for collision detection,
166 this isn't necessarily the bounding box for graphics) */
169 /** The movement that will happen till next frame */
172 /** The collision group */
173 CollisionGroup group;
176 /** this is only here for internal collision detection use (don't touch this
177 from outside collision detection code)
179 This field holds the currently anticipated destination of the object
180 during collision detection */