collision_object.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include "collision/collision_object.hpp"
  18. #include "collision/collision_listener.hpp"
  19. #include "collision/collision_movement_manager.hpp"
  20. #include "supertux/game_object.hpp"
  21. CollisionObject::CollisionObject(CollisionGroup group, CollisionListener& listener) :
  22. m_listener(listener),
  23. m_bbox(),
  24. m_group(group),
  25. m_movement(0.0f, 0.0f),
  26. m_dest(),
  27. m_unisolid(false),
  28. m_pressure(),
  29. m_objects_hit_bottom(),
  30. m_ground_movement_manager(nullptr)
  31. {
  32. }
  33. void
  34. CollisionObject::collision_solid(const CollisionHit& hit)
  35. {
  36. m_listener.collision_solid(hit);
  37. }
  38. bool
  39. CollisionObject::collides(CollisionObject& other, const CollisionHit& hit) const
  40. {
  41. return m_listener.collides(dynamic_cast<GameObject&>(other.m_listener), hit);
  42. }
  43. HitResponse
  44. CollisionObject::collision(CollisionObject& other, const CollisionHit& hit)
  45. {
  46. return m_listener.collision(dynamic_cast<GameObject&>(other.m_listener), hit);
  47. }
  48. void
  49. CollisionObject::collision_tile(uint32_t tile_attributes)
  50. {
  51. m_listener.collision_tile(tile_attributes);
  52. }
  53. void
  54. CollisionObject::collision_moving_object_bottom(CollisionObject& other)
  55. {
  56. if (m_group == COLGROUP_STATIC
  57. || m_group == COLGROUP_MOVING_STATIC)
  58. {
  59. m_objects_hit_bottom.insert(&other);
  60. }
  61. }
  62. void
  63. CollisionObject::notify_object_removal(CollisionObject* other)
  64. {
  65. m_objects_hit_bottom.erase(other);
  66. }
  67. void
  68. CollisionObject::clear_bottom_collision_list()
  69. {
  70. m_objects_hit_bottom.clear();
  71. }
  72. void CollisionObject::propagate_movement(const Vector& movement)
  73. {
  74. for (CollisionObject* other_object : m_objects_hit_bottom) {
  75. if (other_object->get_group() == COLGROUP_STATIC) continue;
  76. m_ground_movement_manager->register_movement(*this, *other_object, movement);
  77. other_object->propagate_movement(movement);
  78. }
  79. }
  80. bool
  81. CollisionObject::is_valid() const
  82. {
  83. return m_listener.listener_is_valid();
  84. }
  85. /* EOF */