pneumatic_platform.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SuperTux - PneumaticPlatform
  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_PNEUMATIC_PLATFORM_HPP
  17. #define HEADER_SUPERTUX_OBJECT_PNEUMATIC_PLATFORM_HPP
  18. #include "object/moving_sprite.hpp"
  19. class PneumaticPlatform;
  20. class PneumaticPlatformChild final : public MovingSprite
  21. {
  22. friend class PneumaticPlatform;
  23. public:
  24. PneumaticPlatformChild(const ReaderMapping& reader, bool left, PneumaticPlatform& parent);
  25. ~PneumaticPlatformChild() override;
  26. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  27. virtual void update(float dt_sec) 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. protected:
  32. PneumaticPlatform& m_parent;
  33. bool m_left;
  34. std::set<GameObject*> m_contacts; /**< objects that are currently pushing on the platform */
  35. private:
  36. PneumaticPlatformChild(const PneumaticPlatformChild&) = delete;
  37. PneumaticPlatformChild& operator=(const PneumaticPlatformChild&) = delete;
  38. };
  39. /** Used to construct a pair of pneumatic platforms: If one is pushed
  40. down, the other one rises */
  41. class PneumaticPlatform final : public GameObject
  42. {
  43. friend class PneumaticPlatformChild;
  44. public:
  45. PneumaticPlatform(const ReaderMapping& mapping);
  46. ~PneumaticPlatform() override;
  47. virtual void draw(DrawingContext& context) override;
  48. virtual void update(float dt_sec) override;
  49. virtual void on_flip(float height) override;
  50. static std::string class_name() { return "pneumatic-platform"; }
  51. virtual std::string get_class_name() const override { return class_name(); }
  52. static std::string display_name() { return _("Pneumatic Platform"); }
  53. virtual std::string get_display_name() const override { return display_name(); }
  54. virtual ObjectSettings get_settings() override;
  55. virtual void after_editor_set() override;
  56. virtual void editor_delete() override;
  57. private:
  58. Vector m_pos;
  59. std::string m_sprite_name;
  60. float m_start_y; /**< vertical start position */
  61. float m_speed_y; /**< vertical speed */
  62. float m_offset_y; /**< vertical offset from the start position in px */
  63. std::vector<PneumaticPlatformChild*> m_children;
  64. private:
  65. PneumaticPlatform(const PneumaticPlatform&) = delete;
  66. PneumaticPlatform& operator=(const PneumaticPlatform&) = delete;
  67. };
  68. #endif
  69. /* EOF */