| 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 |
| 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; |
| 34 | 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 | virtual ~BicyclePlatform(); |
| 59 | |
| 60 | virtual void draw(DrawingContext& context) override; |
| 61 | virtual void update(float dt_sec) override; |
| 62 | |
| 63 | virtual std::string get_class() const override { return "bicycle-platform" ; } |
| 64 | virtual std::string get_display_name() const override { return _("Bicycle Platform" ); } |
| 65 | |
| 66 | virtual ObjectSettings get_settings() override; |
| 67 | virtual void editor_delete() override; |
| 68 | virtual void after_editor_set() override; |
| 69 | |
| 70 | private: |
| 71 | Vector m_center; /**< pivot point */ |
| 72 | float m_radius; /**< radius of circle */ |
| 73 | |
| 74 | float m_angle; /**< current angle */ |
| 75 | float m_angular_speed; /**< angular speed in rad per second */ |
| 76 | |
| 77 | float m_momentum_change_rate; /** Change in momentum every step **/ |
| 78 | |
| 79 | std::vector<BicyclePlatformChild*> m_children; |
| 80 | std::unique_ptr<PathWalker> m_walker; |
| 81 | int m_platforms; |
| 82 | |
| 83 | private: |
| 84 | BicyclePlatform(const BicyclePlatform&) = delete; |
| 85 | BicyclePlatform& operator=(const BicyclePlatform&) = delete; |
| 86 | }; |
| 87 | |
| 88 | #endif |
| 89 | |
| 90 | /* EOF */ |
| 91 | |