scripted_object.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_SCRIPTED_OBJECT_HPP
  17. #define HEADER_SUPERTUX_OBJECT_SCRIPTED_OBJECT_HPP
  18. #include "object/moving_sprite.hpp"
  19. #include "supertux/physic.hpp"
  20. /**
  21. * @scripting
  22. * @summary A ""ScriptedObject"" that was given a name can be controlled by scripts.
  23. * @instances A ""ScriptedObject"" is instantiated by placing a definition inside a level.
  24. It can then be accessed by its name from a script or via ""sector.name"" from the console.
  25. */
  26. class ScriptedObject final : public MovingSprite
  27. {
  28. public:
  29. static void register_class(ssq::VM& vm);
  30. public:
  31. ScriptedObject(const ReaderMapping& mapping);
  32. virtual void update(float dt_sec) override;
  33. virtual void draw(DrawingContext& context) override;
  34. virtual void collision_solid(const CollisionHit& hit) override;
  35. virtual HitResponse collision(MovingObject& other, const CollisionHit& hit) override;
  36. static std::string class_name() { return "scriptedobject"; }
  37. virtual std::string get_class_name() const override { return class_name(); }
  38. virtual std::string get_exposed_class_name() const override { return "ScriptedObject"; }
  39. static std::string display_name() { return _("Scripted Object"); }
  40. virtual std::string get_display_name() const override { return display_name(); }
  41. virtual GameObjectClasses get_class_types() const override { return MovingSprite::get_class_types().add(typeid(ScriptedObject)); }
  42. virtual ObjectSettings get_settings() override;
  43. virtual void on_flip(float height) override;
  44. #ifdef DOXYGEN_SCRIPTING
  45. /**
  46. * @scripting
  47. * @deprecated Use ""get_x()"" instead!
  48. * @description Returns the X coordinate of the object's position.
  49. */
  50. float get_pos_x() const;
  51. /**
  52. * @scripting
  53. * @deprecated Use ""get_y()"" instead!
  54. * @description Returns the Y coordinate of the object's position.
  55. */
  56. float get_pos_y() const;
  57. #endif
  58. /**
  59. * @scripting
  60. * @description Makes the object move in a certain ""x"" and ""y"" direction (with a certain speed).
  61. * @param float $x
  62. * @param float $y
  63. */
  64. void set_velocity(float x, float y);
  65. /**
  66. * @scripting
  67. * @description Returns the X coordinate of the object's velocity.
  68. */
  69. inline float get_velocity_x() const { return physic.get_velocity_x(); }
  70. /**
  71. * @scripting
  72. * @description Returns the Y coordinate of the object's velocity.
  73. */
  74. inline float get_velocity_y() const { return physic.get_velocity_y(); }
  75. /**
  76. * @scripting
  77. * @description Enables or disables gravity, according to the value of ""enabled"".
  78. * @param bool $enabled
  79. */
  80. inline void enable_gravity(bool enabled) { physic.enable_gravity(enabled); }
  81. /**
  82. * @scripting
  83. * @description Returns ""true"" if the object's gravity is enabled.
  84. */
  85. inline bool gravity_enabled() const { return physic.gravity_enabled(); }
  86. /**
  87. * @scripting
  88. * @description Shows or hides the object, according to the value of ""visible"".
  89. * @param bool $visible
  90. */
  91. inline void set_visible(bool visible_) { visible = visible_; }
  92. /**
  93. * @scripting
  94. * @description Returns ""true"" if the object is visible.
  95. */
  96. inline bool is_visible() const { return visible; }
  97. /**
  98. * @scripting
  99. * @description Changes the solidity, according to the value of ""solid"".
  100. * @param bool $solid
  101. */
  102. void set_solid(bool solid);
  103. /**
  104. * @scripting
  105. * @description Returns ""true"" if the object is solid.
  106. */
  107. inline bool is_solid() const { return solid; }
  108. private:
  109. Physic physic;
  110. /**
  111. * @scripting
  112. * @description Determines whether the object is solid.
  113. */
  114. bool solid;
  115. bool physic_enabled;
  116. /**
  117. * @scripting
  118. * @description Determines whether the object is visible.
  119. */
  120. bool visible;
  121. std::string hit_script;
  122. bool new_vel_set;
  123. Vector new_vel;
  124. Vector new_size;
  125. private:
  126. ScriptedObject(const ScriptedObject&) = delete;
  127. ScriptedObject& operator=(const ScriptedObject&) = delete;
  128. };
  129. #endif
  130. /* EOF */