cloud_particle_system.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // Copyright (C) 2024 bruhmoent
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYSTEM_HPP
  18. #define HEADER_SUPERTUX_OBJECT_CLOUD_PARTICLE_SYSTEM_HPP
  19. #include "object/particlesystem.hpp"
  20. #include "video/surface_ptr.hpp"
  21. class ReaderMapping;
  22. /**
  23. * @scripting
  24. * @summary A ""CloudParticleSystem"" that was given a name can be controlled by scripts.
  25. * @instances A ""CloudParticleSystem"" is instantiated by placing a definition inside a level.
  26. It can then be accessed by its name from a script or via ""sector.name"" from the console.
  27. */
  28. class CloudParticleSystem final : public ParticleSystem
  29. {
  30. public:
  31. static void register_class(ssq::VM& vm);
  32. public:
  33. CloudParticleSystem();
  34. CloudParticleSystem(const ReaderMapping& reader);
  35. ~CloudParticleSystem() override;
  36. void init();
  37. virtual void update(float dt_sec) override;
  38. virtual void draw(DrawingContext& context) override;
  39. static std::string class_name() { return "particles-clouds"; }
  40. virtual std::string get_class_name() const override { return class_name(); }
  41. virtual std::string get_exposed_class_name() const override { return "CloudParticleSystem"; }
  42. static std::string display_name() { return _("Cloud Particles"); }
  43. virtual std::string get_display_name() const override { return display_name(); }
  44. virtual GameObjectClasses get_class_types() const override { return ParticleSystem::get_class_types().add(typeid(CloudParticleSystem)); }
  45. virtual ObjectSettings get_settings() override;
  46. virtual const std::string get_icon_path() const override {
  47. return "images/engine/editor/clouds.png";
  48. }
  49. /**
  50. * @scripting
  51. * @description Smoothly changes the clouds' X and Y speed to the given value in ""time"" seconds.
  52. * @param float $speed_x
  53. * @param float $speed_y
  54. * @param float $time
  55. */
  56. void fade_speed(float speed_x, float speed_y, float time);
  57. /**
  58. * @scripting
  59. * @description Smoothly changes the amount of particles to the given value in ""time"" seconds.
  60. * @param int $amount
  61. * @param float $time
  62. * @param float $time_between
  63. */
  64. void fade_amount(int amount, float time, float time_between);
  65. /**
  66. * @scripting
  67. * @description Smoothly changes the amount of particles to the given value in ""time"" seconds.
  68. * @param int $amount
  69. * @param float $time
  70. */
  71. inline void set_amount(int amount, float time) { fade_amount(amount, time, 0.f); }
  72. // Minimum and maximum multiplier for the amount of clouds
  73. static int constexpr const max_amount = 500;
  74. static int constexpr const min_amount = 0;
  75. /**
  76. * @scripting
  77. * @description Sets the horizontal speed of the cloud particles.
  78. * @param float $speed
  79. */
  80. inline void set_x_speed(float speed) { m_current_speed_x = speed; }
  81. /**
  82. * @scripting
  83. * @description Gets the horizontal speed of the cloud particles.
  84. * @return float
  85. */
  86. inline float get_x_speed() const { return m_current_speed_x; }
  87. /**
  88. * @scripting
  89. * @description Sets the vertical speed of the cloud particles.
  90. * @param float $speed
  91. */
  92. inline void set_y_speed(float speed) { m_current_speed_y = speed; }
  93. /**
  94. * @scripting
  95. * @description Gets the vertical speed of the cloud particles.
  96. * @return float
  97. */
  98. inline float get_y_speed() const { return m_current_speed_y; }
  99. /**
  100. * @scripting
  101. * @description Sets the fog's opacity.
  102. * @param float opacity
  103. */
  104. void set_fog_opacity(float opacity);
  105. /**
  106. * @scripting
  107. * @description Gets the fog's opacity.
  108. * @return float
  109. */
  110. inline float get_fog_opacity() const { return m_fog_opacity; }
  111. private:
  112. /** Returns the amount that got inserted (In case max_amount got hit) */
  113. int add_clouds(int amount, float fade_time);
  114. /** Returns the amount that got removed (In case min_amount got hit) */
  115. int remove_clouds(int amount, float fade_time);
  116. /** Applies the fog effect based on the intensity */
  117. void apply_fog_effect(DrawingContext& context);
  118. private:
  119. class CloudParticle : public Particle
  120. {
  121. public:
  122. float speed;
  123. float target_alpha;
  124. float target_time_remaining;
  125. CloudParticle() :
  126. speed(),
  127. target_alpha(),
  128. target_time_remaining()
  129. {}
  130. };
  131. SurfacePtr cloud_image;
  132. float m_current_speed_x;
  133. float m_target_speed_x;
  134. float m_speed_fade_time_remaining_x;
  135. float m_current_speed_y;
  136. float m_target_speed_y;
  137. float m_speed_fade_time_remaining_y;
  138. int m_current_amount;
  139. int m_current_real_amount;
  140. float m_fog_opacity;
  141. private:
  142. CloudParticleSystem(const CloudParticleSystem&) = delete;
  143. CloudParticleSystem& operator=(const CloudParticleSystem&) = delete;
  144. };
  145. #endif
  146. /* EOF */