rain_particle_system.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SuperTux
  2. // Copyright (C) 2020 A. Semphris <semphris@protonmail.com>
  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_RAIN_PARTICLE_SYSTEM_HPP
  17. #define HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP
  18. #include "math/easing.hpp"
  19. #include "object/particlesystem_interactive.hpp"
  20. #include "scripting/rain.hpp"
  21. #include "video/surface_ptr.hpp"
  22. class RainParticleSystem final :
  23. public ParticleSystem_Interactive,
  24. public ExposedObject<RainParticleSystem, scripting::Rain>
  25. {
  26. public:
  27. RainParticleSystem();
  28. RainParticleSystem(const ReaderMapping& reader);
  29. ~RainParticleSystem() override;
  30. virtual void draw(DrawingContext& context) override;
  31. void init();
  32. virtual void update(float dt_sec) override;
  33. static std::string class_name() { return "particles-rain"; }
  34. virtual std::string get_class_name() const override { return class_name(); }
  35. static std::string display_name() { return _("Rain Particles"); }
  36. virtual std::string get_display_name() const override { return display_name(); }
  37. virtual ObjectSettings get_settings() override;
  38. void fade_speed(float new_speed, float fade_time);
  39. void fade_angle(float new_angle, float fade_time, easing ease_func);
  40. void fade_amount(float new_amount, float fade_time);
  41. virtual const std::string get_icon_path() const override {
  42. return "images/engine/editor/rain.png";
  43. }
  44. // Minimum and maximum multiplier for the amount of particles (intensity)
  45. static float constexpr const max_amount = 5.0f;
  46. static float constexpr const min_amount = 0.1f;
  47. // Minimum value of m_current_amount for the fog to be > 0
  48. static float constexpr const fog_start_amount = 1.0f;
  49. // When m_current_amount == max_amount, fog is this value
  50. static float constexpr const fog_max_value = 0.6f;
  51. virtual void expose(HSQUIRRELVM vm, SQInteger table_idx) override {
  52. ExposedObject<RainParticleSystem, scripting::Rain>::expose(vm, table_idx);
  53. }
  54. virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx) override {
  55. ExposedObject<RainParticleSystem, scripting::Rain>::unexpose(vm, table_idx);
  56. }
  57. private:
  58. void set_amount(float amount);
  59. void set_angle(float angle);
  60. private:
  61. class RainParticle : public Particle
  62. {
  63. public:
  64. float speed;
  65. RainParticle() :
  66. speed()
  67. {}
  68. };
  69. SurfacePtr rainimages[2];
  70. float m_current_speed;
  71. float m_target_speed;
  72. float m_speed_fade_time_remaining;
  73. float m_begin_angle;
  74. float m_current_angle;
  75. float m_target_angle;
  76. float m_angle_fade_time_remaining;
  77. float m_angle_fade_time_total;
  78. easing m_angle_easing;
  79. float m_current_amount;
  80. float m_target_amount;
  81. float m_amount_fade_time_remaining;
  82. float m_current_real_amount;
  83. private:
  84. RainParticleSystem(const RainParticleSystem&) = delete;
  85. RainParticleSystem& operator=(const RainParticleSystem&) = delete;
  86. };
  87. #endif
  88. /* EOF */