supertux
rain_particle_system.hpp
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 
17 #ifndef HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP
18 #define HEADER_SUPERTUX_OBJECT_RAIN_PARTICLE_SYSTEM_HPP
19 
20 #include "object/particlesystem_interactive.hpp"
21 
22 #include "math/easing.hpp"
23 #include "video/surface_ptr.hpp"
24 
32 {
33 public:
34  static void register_class(ssq::VM& vm);
35 
36 public:
38  RainParticleSystem(const ReaderMapping& reader);
39  ~RainParticleSystem() override;
40 
41  virtual void draw(DrawingContext& context) override;
42 
43  void init();
44  virtual void update(float dt_sec) override;
45 
46  static std::string class_name() { return "particles-rain"; }
47  virtual std::string get_class_name() const override { return class_name(); }
48  virtual std::string get_exposed_class_name() const override { return "RainParticleSystem"; }
49  static std::string display_name() { return _("Rain Particles"); }
50  virtual std::string get_display_name() const override { return display_name(); }
52  virtual ObjectSettings get_settings() override;
53 
60  void fade_speed(float speed, float time);
67  void fade_amount(float amount, float time);
75  void fade_angle(float angle, float time, const std::string& ease);
76 
78  void fade_angle(float new_angle, float fade_time, easing ease_func);
79 
80  virtual const std::string get_icon_path() const override {
81  return "images/engine/editor/rain.png";
82  }
83 
84  // Minimum and maximum multiplier for the amount of particles (intensity)
85  static float constexpr const max_amount = 5.0f;
86  static float constexpr const min_amount = 0.1f;
87 
88  // Minimum value of m_current_amount for the fog to be > 0
89  static float constexpr const fog_start_amount = 1.0f;
90 
91  // When m_current_amount == max_amount, fog is this value
92  static float constexpr const fog_max_value = 0.6f;
93 
94 private:
95  void set_amount(float amount);
96  void set_angle(float angle);
97 
98 private:
99  class RainParticle : public Particle
100  {
101  public:
102  float speed;
103 
104  RainParticle() :
105  speed()
106  {}
107  };
108 
109  SurfacePtr rainimages[2];
110 
111  float m_current_speed;
112  float m_target_speed;
113  float m_speed_fade_time_remaining;
114 
115  float m_begin_angle;
116  float m_current_angle;
117  float m_target_angle;
118  float m_angle_fade_time_remaining;
119  float m_angle_fade_time_total;
120  easing m_angle_easing;
121 
122  float m_current_amount;
123  float m_target_amount;
124  float m_amount_fade_time_remaining;
125 
126  float m_current_real_amount;
127 
128 private:
129  RainParticleSystem(const RainParticleSystem&) = delete;
130  RainParticleSystem& operator=(const RainParticleSystem&) = delete;
131 };
132 
133 #endif
134 
135 /* EOF */
void fade_amount(float amount, float time)
Smoothly changes the amount of particles to the given value in ""time"" seconds.
Definition: rain_particle_system.cpp:252
This is an alternative class for particle systems.
Definition: particlesystem_interactive.hpp:39
void fade_angle(float angle, float time, const std::string &ease)
Smoothly changes the angle of the rain the given value in ""time"" seconds, according to the provided...
Definition: rain_particle_system.cpp:267
Definition: particlesystem.hpp:86
Definition: object_settings.hpp:39
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: particlesystem_interactive.hpp:50
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: rain_particle_system.cpp:289
A ""RainParticleSystem"" that was given a name can be controlled by scripts.
Definition: rain_particle_system.hpp:31
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: rain_particle_system.cpp:144
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: rain_particle_system.hpp:51
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: rain_particle_system.hpp:50
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
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void fade_speed(float speed, float time)
Smoothly changes the rain speed to the given value in ""time"" seconds.
Definition: rain_particle_system.cpp:238