snow_particle_system.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_SNOW_PARTICLE_SYSTEM_HPP
  18. #define HEADER_SUPERTUX_OBJECT_SNOW_PARTICLE_SYSTEM_HPP
  19. #include "object/particlesystem.hpp"
  20. #include "supertux/timer.hpp"
  21. class ReaderMapping;
  22. class SnowParticleSystem final : public ParticleSystem
  23. {
  24. public:
  25. SnowParticleSystem();
  26. SnowParticleSystem(const ReaderMapping& reader);
  27. ~SnowParticleSystem() override;
  28. virtual void update(float dt_sec) override;
  29. static std::string class_name() { return "particles-snow"; }
  30. virtual std::string get_class_name() const override { return class_name(); }
  31. static std::string display_name() { return _("Snow Particles"); }
  32. virtual std::string get_display_name() const override { return display_name(); }
  33. virtual ObjectSettings get_settings() override;
  34. virtual const std::string get_icon_path() const override
  35. {
  36. return "images/engine/editor/snow.png";
  37. }
  38. private:
  39. void init();
  40. class SnowParticle : public Particle
  41. {
  42. public:
  43. float speed;
  44. float wobble;
  45. float anchorx;
  46. float drift_speed;
  47. // Turning speed.
  48. float spin_speed;
  49. // For inertia.
  50. unsigned int flake_size;
  51. SnowParticle() :
  52. speed(),
  53. wobble(),
  54. anchorx(),
  55. drift_speed(),
  56. spin_speed(),
  57. flake_size()
  58. {}
  59. };
  60. // Wind is simulated in discrete "gusts",
  61. // gust states:
  62. enum State {
  63. ATTACKING,
  64. DECAYING,
  65. SUSTAINING,
  66. RELEASING,
  67. RESTING,
  68. MAX_STATE
  69. };
  70. private:
  71. State m_state;
  72. // Gust state delay timer.
  73. Timer m_timer;
  74. // Peak magnitude of gust is gust_onset * randf(5).
  75. float m_gust_onset;
  76. // Current blowing velocity of gust.
  77. float m_gust_current_velocity;
  78. float m_wind_speed;
  79. float m_epsilon; // Velocity changes by up to this much each tick.
  80. float m_spin_speed;
  81. float m_state_length; // Interval for how long to affect the particles with wind.
  82. SurfacePtr m_snowimages[3];
  83. private:
  84. SnowParticleSystem(const SnowParticleSystem&) = delete;
  85. SnowParticleSystem& operator=(const SnowParticleSystem&) = delete;
  86. };
  87. #endif
  88. /* EOF */