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
26class Sector;
27
28/** Base class for all dynamic/moving game objects. This class
29 contains things for handling the bounding boxes and collision
30 feedback. */
31class MovingObject : public GameObject,
32 public CollisionListener
33{
34 friend class Sector;
35 friend class CollisionSystem;
36
37public:
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
100protected:
101 void set_group(CollisionGroup group)
102 {
103 m_col.m_group = group;
104 }
105
106protected:
107 CollisionObject m_col;
108
109private:
110 MovingObject(const MovingObject&) = delete;
111 MovingObject& operator=(const MovingObject&) = delete;
112};
113
114#endif
115
116/* EOF */
117