moving_object.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
  17. #define HEADER_SUPERTUX_SUPERTUX_MOVING_OBJECT_HPP
  18. #include "collision/collision_hit.hpp"
  19. #include "collision/collision_object.hpp"
  20. #include "collision/collision_listener.hpp"
  21. #include "math/rectf.hpp"
  22. #include "supertux/game_object.hpp"
  23. class Dispenser;
  24. class Sector;
  25. /** Base class for all dynamic/moving game objects. This class
  26. contains things for handling the bounding boxes and collision
  27. feedback. */
  28. class MovingObject : public GameObject,
  29. public CollisionListener
  30. {
  31. friend class ResizeMarker;
  32. friend class Sector;
  33. friend class CollisionSystem;
  34. public:
  35. MovingObject();
  36. MovingObject(const ReaderMapping& reader);
  37. ~MovingObject() override;
  38. virtual void collision_solid(const CollisionHit& /*hit*/) override
  39. {
  40. }
  41. virtual bool collides(GameObject& /*other*/, const CollisionHit& /*hit*/) const override
  42. {
  43. return true;
  44. }
  45. virtual void collision_tile(uint32_t /*tile_attributes*/) override
  46. {
  47. }
  48. virtual void set_pos(const Vector& pos)
  49. {
  50. m_col.set_pos(pos);
  51. }
  52. virtual void move_to(const Vector& pos)
  53. {
  54. m_col.move_to(pos);
  55. }
  56. virtual bool listener_is_valid() const override { return is_valid(); }
  57. Vector get_pos() const
  58. {
  59. return m_col.m_bbox.p1();
  60. }
  61. const Rectf& get_bbox() const
  62. {
  63. return m_col.m_bbox;
  64. }
  65. const Vector& get_movement() const
  66. {
  67. return m_col.get_movement();
  68. }
  69. CollisionGroup get_group() const
  70. {
  71. return m_col.m_group;
  72. }
  73. CollisionObject* get_collision_object() {
  74. return &m_col;
  75. }
  76. const CollisionObject* get_collision_object() const {
  77. return &m_col;
  78. }
  79. void set_parent_dispenser(Dispenser* dispenser);
  80. Dispenser* get_parent_dispenser() const { return m_parent_dispenser; }
  81. static std::string class_name() { return "moving-object"; }
  82. virtual std::string get_class_name() const override { return class_name(); }
  83. virtual ObjectSettings get_settings() override;
  84. virtual void editor_select() override;
  85. virtual void on_flip(float height) override;
  86. virtual int get_layer() const = 0;
  87. protected:
  88. void set_group(CollisionGroup group)
  89. {
  90. m_col.m_group = group;
  91. }
  92. protected:
  93. CollisionObject m_col;
  94. Dispenser* m_parent_dispenser;
  95. private:
  96. MovingObject(const MovingObject&) = delete;
  97. MovingObject& operator=(const MovingObject&) = delete;
  98. };
  99. #endif
  100. /* EOF */