bicycle_platform.hpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SuperTux - BicyclePlatform
  2. // Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.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_OBJECT_BICYCLE_PLATFORM_HPP
  17. #define HEADER_SUPERTUX_OBJECT_BICYCLE_PLATFORM_HPP
  18. #include "object/path_walker.hpp"
  19. #include "object/moving_sprite.hpp"
  20. class BicyclePlatform;
  21. class BicyclePlatformChild : public MovingSprite
  22. {
  23. friend class BicyclePlatform;
  24. public:
  25. BicyclePlatformChild(const ReaderMapping& reader, float angle_offset, BicyclePlatform& parent);
  26. virtual void update(float dt_sec) override;
  27. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  28. virtual bool is_saveable() const override { return false; }
  29. virtual void on_flip(float height) override;
  30. virtual void editor_delete() override;
  31. private:
  32. BicyclePlatform& m_parent;
  33. float m_angle_offset;
  34. float m_momentum; /** angular momentum in rad per second per second*/
  35. std::set<GameObject*> m_contacts; /**< objects that are currently pushing on the platform */
  36. private:
  37. BicyclePlatformChild(const BicyclePlatformChild&) = delete;
  38. BicyclePlatformChild& operator=(const BicyclePlatformChild&) = delete;
  39. };
  40. /**
  41. * Used to construct a pair of bicycle platforms: If one is pushed down, the other one rises
  42. */
  43. class BicyclePlatform final : public GameObject
  44. {
  45. friend class BicyclePlatformChild;
  46. public:
  47. BicyclePlatform(const ReaderMapping& reader);
  48. ~BicyclePlatform() override;
  49. virtual void draw(DrawingContext& context) override;
  50. virtual void update(float dt_sec) override;
  51. virtual void on_flip(float height) override;
  52. static std::string class_name() { return "bicycle-platform"; }
  53. virtual std::string get_class_name() const override { return class_name(); }
  54. static std::string display_name() { return _("Bicycle Platform"); }
  55. virtual std::string get_display_name() const override { return display_name(); }
  56. virtual ObjectSettings get_settings() override;
  57. virtual void editor_delete() override;
  58. virtual void after_editor_set() override;
  59. private:
  60. Vector m_center; /**< pivot point */
  61. float m_radius; /**< radius of circle */
  62. float m_angle; /**< current angle */
  63. float m_angular_speed; /**< angular speed in rad per second */
  64. float m_momentum_change_rate; /** Change in momentum every step **/
  65. std::vector<BicyclePlatformChild*> m_children;
  66. std::unique_ptr<PathWalker> m_walker;
  67. int m_platforms;
  68. private:
  69. BicyclePlatform(const BicyclePlatform&) = delete;
  70. BicyclePlatform& operator=(const BicyclePlatform&) = delete;
  71. };
  72. #endif
  73. /* EOF */