supertux
collision_object.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2018 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_COLLISION_COLLISION_OBJECT_HPP
19 #define HEADER_SUPERTUX_COLLISION_COLLISION_OBJECT_HPP
20 
21 #include <stdint.h>
22 
23 #include "collision/collision_group.hpp"
24 #include "collision/collision_hit.hpp"
25 #include "math/rectf.hpp"
26 
27 class CollisionListener;
28 class GameObject;
29 
31 {
32  friend class CollisionSystem;
33 
34 public:
35  CollisionObject(CollisionGroup group, CollisionListener& parent);
36 
38  void collision_solid(const CollisionHit& hit);
39 
43  bool collides(CollisionObject& other, const CollisionHit& hit) const;
44 
46  HitResponse collision(CollisionObject& other, const CollisionHit& hit);
47 
49  void collision_tile(uint32_t tile_attributes);
50 
52  const Rectf& get_bbox() const
53  {
54  return m_bbox;
55  }
56 
57  const Vector& get_movement() const
58  {
59  return m_movement;
60  }
61 
65  void set_pos(const Vector& pos)
66  {
67  m_dest.move(pos - get_pos());
68  m_bbox.set_pos(pos);
69  }
70 
71  Vector get_pos() const
72  {
73  return m_bbox.p1();
74  }
75 
79  void move_to(const Vector& pos)
80  {
81  set_pos(pos);
82  }
83 
87  void set_width(float w)
88  {
89  m_dest.set_width(w);
90  m_bbox.set_width(w);
91  }
92 
96  void set_size(float w, float h)
97  {
98  m_dest.set_size(w, h);
99  m_bbox.set_size(w, h);
100  }
101 
102  CollisionGroup get_group() const
103  {
104  return m_group;
105  }
106 
107  bool is_valid() const;
108 
109  CollisionListener& get_listener()
110  {
111  return m_listener;
112  }
113 
114 private:
115  CollisionListener& m_listener;
116 
117 public:
121 
124 
126  CollisionGroup m_group;
127 
128 private:
134  Rectf m_dest;
135 
136 private:
137  CollisionObject(const CollisionObject&) = delete;
138  CollisionObject& operator=(const CollisionObject&) = delete;
139 };
140 
141 #endif
142 
143 /* EOF */
HitResponse collision(CollisionObject &other, const CollisionHit &hit)
this function is called when the object collided with any other object
Definition: collision_object.cpp:45
CollisionGroup m_group
The collision group.
Definition: collision_object.hpp:126
void set_size(float w, float h)
sets the moving object&#39;s bbox to a specific size.
Definition: collision_object.hpp:96
Vector m_movement
The movement that will happen till next frame.
Definition: collision_object.hpp:123
bool collides(CollisionObject &other, const CollisionHit &hit) const
when 2 objects collided, we will first call the pre_collision_check functions of both objects that ca...
Definition: collision_object.cpp:39
Simple two dimensional vector.
Definition: vector.hpp:24
Definition: collision_listener.hpp:23
void set_width(float w)
sets the moving object&#39;s bbox to a specific width.
Definition: collision_object.hpp:87
const Rectf & get_bbox() const
returns the bounding box of the Object
Definition: collision_object.hpp:52
void move_to(const Vector &pos)
moves entire object to a specific position, including all points those the object has...
Definition: collision_object.hpp:79
Definition: collision_system.hpp:32
Rectf m_bbox
The bounding box of the object (as used for collision detection, this isn&#39;t necessarily the bounding ...
Definition: collision_object.hpp:120
void set_pos(const Vector &pos)
places the moving object at a specific position.
Definition: collision_object.hpp:65
Definition: rectf.hpp:29
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
void collision_solid(const CollisionHit &hit)
this function is called when the object collided with something solid
Definition: collision_object.cpp:33
void collision_tile(uint32_t tile_attributes)
called when tiles with special attributes have been touched
Definition: collision_object.cpp:51
Definition: collision_object.hpp:30
This class collects data about a collision.
Definition: collision_hit.hpp:44