| 1 | // SuperTux |
| 2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.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_PLATFORM_HPP |
| 18 | #define |
| 19 | |
| 20 | #include "object/moving_sprite.hpp" |
| 21 | #include "object/path_object.hpp" |
| 22 | #include "squirrel/exposed_object.hpp" |
| 23 | #include "scripting/platform.hpp" |
| 24 | |
| 25 | /** This class is the base class for platforms that tux can stand |
| 26 | on */ |
| 27 | class Platform : public MovingSprite, |
| 28 | public ExposedObject<Platform, scripting::Platform>, |
| 29 | public PathObject |
| 30 | { |
| 31 | public: |
| 32 | Platform(const ReaderMapping& reader); |
| 33 | Platform(const ReaderMapping& reader, const std::string& default_sprite); |
| 34 | |
| 35 | virtual void finish_construction() override; |
| 36 | |
| 37 | virtual ObjectSettings get_settings() override; |
| 38 | |
| 39 | virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; |
| 40 | virtual void update(float dt_sec) override; |
| 41 | |
| 42 | virtual void move_to(const Vector& pos) override; |
| 43 | |
| 44 | virtual std::string get_class() const override { return "platform" ; } |
| 45 | virtual std::string get_display_name() const override { return _("Platform" ); } |
| 46 | |
| 47 | virtual void editor_update() override; |
| 48 | |
| 49 | const Vector& get_speed() const { return m_speed; } |
| 50 | |
| 51 | /** @name Scriptable Methods |
| 52 | @{ */ |
| 53 | |
| 54 | /** Move platform until at given node, then stop */ |
| 55 | void goto_node(int node_no); |
| 56 | |
| 57 | /** Start moving platform */ |
| 58 | void start_moving(); |
| 59 | |
| 60 | /** Stop platform at next node */ |
| 61 | void stop_moving(); |
| 62 | |
| 63 | /** @} */ |
| 64 | |
| 65 | private: |
| 66 | Vector m_speed; |
| 67 | |
| 68 | /** true if Platform will automatically pick a destination based on |
| 69 | collisions and current Player position */ |
| 70 | bool m_automatic; |
| 71 | |
| 72 | /** true if a Player touched the Platform during the last round of |
| 73 | collision detections */ |
| 74 | bool m_player_contact; |
| 75 | |
| 76 | /** true if a Player touched the Platform during the round before |
| 77 | the last round of collision detections */ |
| 78 | bool m_last_player_contact; |
| 79 | |
| 80 | private: |
| 81 | Platform(const Platform&) = delete; |
| 82 | Platform& operator=(const Platform&) = delete; |
| 83 | }; |
| 84 | |
| 85 | #endif |
| 86 | |
| 87 | /* EOF */ |
| 88 | |