platform.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef HEADER_SUPERTUX_OBJECT_PLATFORM_HPP
  17. #define HEADER_SUPERTUX_OBJECT_PLATFORM_HPP
  18. #include "object/moving_sprite.hpp"
  19. #include "object/path_object.hpp"
  20. #include "squirrel/exposed_object.hpp"
  21. #include "scripting/platform.hpp"
  22. /** This class is the base class for platforms that tux can stand
  23. on */
  24. class Platform : public MovingSprite,
  25. public ExposedObject<Platform, scripting::Platform>,
  26. public PathObject
  27. {
  28. public:
  29. Platform(const ReaderMapping& reader);
  30. Platform(const ReaderMapping& reader, const std::string& default_sprite);
  31. virtual void finish_construction() override;
  32. virtual ObjectSettings get_settings() override;
  33. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  34. virtual void update(float dt_sec) override;
  35. virtual void move_to(const Vector& pos) override;
  36. static std::string class_name() { return "platform"; }
  37. virtual std::string get_class_name() const override { return class_name(); }
  38. static std::string display_name() { return _("Platform"); }
  39. virtual std::string get_display_name() const override { return display_name(); }
  40. virtual void editor_update() override;
  41. virtual void on_flip(float height) override;
  42. void save_state() override;
  43. void check_state() override;
  44. const Vector& get_speed() const { return m_speed; }
  45. /** @name Scriptable Methods
  46. @{ */
  47. /** Move platform until at given node, then stop */
  48. void goto_node(int node_idx);
  49. /** Move platform instantly to given node */
  50. void jump_to_node(int node_idx, bool instantaneous = false);
  51. /** Start moving platform */
  52. void start_moving();
  53. /** Stop platform at next node */
  54. void stop_moving();
  55. /** @} */
  56. private:
  57. Vector m_speed;
  58. /** true if Platform will automatically pick a destination based on
  59. collisions and current Player position */
  60. bool m_automatic;
  61. /** true if a Player touched the Platform during the last round of
  62. collision detections */
  63. bool m_player_contact;
  64. /** true if a Player touched the Platform during the round before
  65. the last round of collision detections */
  66. bool m_last_player_contact;
  67. int m_starting_node;
  68. private:
  69. Platform(const Platform&) = delete;
  70. Platform& operator=(const Platform&) = delete;
  71. };
  72. #endif
  73. /* EOF */