supertux
moving_object.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16 
17 #ifndef HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
19 
20 #include "collision/collision_hit.hpp"
21 #include "collision/collision_object.hpp"
22 #include "collision/collision_listener.hpp"
23 #include "math/rectf.hpp"
24 #include "supertux/game_object.hpp"
25 
26 class Sector;
27 
31 class MovingObject : public GameObject,
32  public CollisionListener
33 {
34  friend class Sector;
35  friend class CollisionSystem;
36 
37 public:
38  MovingObject();
39  MovingObject(const ReaderMapping& reader);
40  virtual ~MovingObject();
41 
42  virtual void collision_solid(const CollisionHit& /*hit*/) override
43  {
44  }
45 
46  virtual bool collides(GameObject& /*other*/, const CollisionHit& /*hit*/) const override
47  {
48  return true;
49  }
50 
51  virtual void collision_tile(uint32_t /*tile_attributes*/) override
52  {
53  }
54 
55  virtual void set_pos(const Vector& pos)
56  {
57  m_col.set_pos(pos);
58  }
59 
60  virtual void move_to(const Vector& pos)
61  {
62  m_col.move_to(pos);
63  }
64 
65  virtual bool listener_is_valid() const override { return is_valid(); }
66 
67  Vector get_pos() const
68  {
69  return m_col.m_bbox.p1();
70  }
71 
72  const Rectf& get_bbox() const
73  {
74  return m_col.m_bbox;
75  }
76 
77  const Vector& get_movement() const
78  {
79  return m_col.m_movement;
80  }
81 
82  CollisionGroup get_group() const
83  {
84  return m_col.m_group;
85  }
86 
87  CollisionObject* get_collision_object() {
88  return &m_col;
89  }
90 
91  const CollisionObject* get_collision_object() const {
92  return &m_col;
93  }
94 
95  virtual std::string get_class() const override { return "moving-object"; }
96  virtual ObjectSettings get_settings() override;
97 
98  virtual void editor_select() override;
99 
100 protected:
101  void set_group(CollisionGroup group)
102  {
103  m_col.m_group = group;
104  }
105 
106 protected:
107  CollisionObject m_col;
108 
109 private:
110  MovingObject(const MovingObject&) = delete;
111  MovingObject& operator=(const MovingObject&) = delete;
112 };
113 
114 #endif
115 
116 /* EOF */
CollisionGroup m_group
The collision group.
Definition: collision_object.hpp:126
Vector m_movement
The movement that will happen till next frame.
Definition: collision_object.hpp:123
virtual void collision_solid(const CollisionHit &) override
this function is called when the object collided with something solid
Definition: moving_object.hpp:42
Simple two dimensional vector.
Definition: vector.hpp:24
Definition: collision_listener.hpp:23
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: object_settings.hpp:35
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
Represents one of (potentially) multiple, separate parts of a Level.
Definition: sector.hpp:49
void set_pos(const Vector &pos)
places the moving object at a specific position.
Definition: collision_object.hpp:65
Definition: rectf.hpp:29
bool is_valid() const
returns true if the object is not scheduled to be removed yet
Definition: game_object.hpp:99
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
virtual void collision_tile(uint32_t) override
called when tiles with special attributes have been touched
Definition: moving_object.hpp:51
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:31
Definition: collision_object.hpp:30
virtual bool collides(GameObject &, const CollisionHit &) const override
when 2 objects collided, we will first call the pre_collision_check functions of both objects that ca...
Definition: moving_object.hpp:46
virtual void editor_select() override
The user clicked on the object in the editor and selected it.
Definition: moving_object.cpp:54
Definition: reader_mapping.hpp:31
This class collects data about a collision.
Definition: collision_hit.hpp:44