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