supertux
snow_particle_system.hpp
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 
18 #ifndef HEADER_SUPERTUX_OBJECT_SNOW_PARTICLE_SYSTEM_HPP
19 #define HEADER_SUPERTUX_OBJECT_SNOW_PARTICLE_SYSTEM_HPP
20 
21 #include "object/particlesystem.hpp"
22 #include "supertux/timer.hpp"
23 
24 class ReaderMapping;
25 
26 class SnowParticleSystem final : public ParticleSystem
27 {
28 public:
30  SnowParticleSystem(const ReaderMapping& reader);
31  ~SnowParticleSystem() override;
32 
33  virtual void update(float dt_sec) override;
34 
35  static std::string class_name() { return "particles-snow"; }
36  virtual std::string get_class_name() const override { return class_name(); }
37  static std::string display_name() { return _("Snow Particles"); }
38  virtual std::string get_display_name() const override { return display_name(); }
39  virtual GameObjectClasses get_class_types() const override { return ParticleSystem::get_class_types().add(typeid(SnowParticleSystem)); }
40  virtual ObjectSettings get_settings() override;
41 
42  virtual const std::string get_icon_path() const override
43  {
44  return "images/engine/editor/snow.png";
45  }
46 
47 private:
48  void init();
49 
50  class SnowParticle : public Particle
51  {
52  public:
53  float speed;
54  float wobble;
55  float anchorx;
56  float drift_speed;
57 
58  // Turning speed.
59  float spin_speed;
60 
61  // For inertia.
62  unsigned int flake_size;
63 
64  SnowParticle() :
65  speed(),
66  wobble(),
67  anchorx(),
68  drift_speed(),
69  spin_speed(),
70  flake_size()
71  {}
72  };
73 
74  // Wind is simulated in discrete "gusts",
75  // gust states:
76  enum State {
77  ATTACKING,
78  DECAYING,
79  SUSTAINING,
80  RELEASING,
81  RESTING,
82  MAX_STATE
83  };
84 
85 private:
86  State m_state;
87 
88  // Gust state delay timer.
89  Timer m_timer;
90 
91  // Peak magnitude of gust is gust_onset * randf(5).
92  float m_gust_onset;
93 
94  // Current blowing velocity of gust.
95  float m_gust_current_velocity;
96 
97  float m_wind_speed;
98  float m_epsilon; // Velocity changes by up to this much each tick.
99  float m_spin_speed;
100  float m_state_length; // Interval for how long to affect the particles with wind.
101 
102  SurfacePtr m_snowimages[3];
103 
104 private:
105  SnowParticleSystem(const SnowParticleSystem&) = delete;
106  SnowParticleSystem& operator=(const SnowParticleSystem&) = delete;
107 };
108 
109 #endif
110 
111 /* EOF */
Definition: snow_particle_system.hpp:26
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: snow_particle_system.hpp:38
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it&#39;s state.
Definition: snow_particle_system.cpp:125
Definition: particlesystem.hpp:86
Definition: object_settings.hpp:39
This is the base class for particle systems.
Definition: particlesystem.hpp:49
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: snow_particle_system.hpp:39
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: particlesystem.hpp:66
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
Definition: reader_mapping.hpp:32