supertux
particlesystem.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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_PARTICLESYSTEM_HPP
18 #define HEADER_SUPERTUX_OBJECT_PARTICLESYSTEM_HPP
19 
20 #include <vector>
21 
22 #include "math/vector.hpp"
23 #include "supertux/game_object.hpp"
24 #include "video/surface_ptr.hpp"
25 
26 class ReaderMapping;
27 
49 class ParticleSystem : public GameObject
50 {
51 public:
52  static void register_class(ssq::VM& vm);
53 
54 public:
55  ParticleSystem(const ReaderMapping& reader, float max_particle_size = 60);
56  ParticleSystem(float max_particle_size = 60);
57  ~ParticleSystem() override;
58 
59  virtual void draw(DrawingContext& context) override;
60 
61  static std::string class_name() { return "particle-system"; }
62  virtual std::string get_class_name() const override { return class_name(); }
63  virtual std::string get_exposed_class_name() const override { return "ParticleSystem"; }
64  static std::string display_name() { return _("Particle system"); }
65  virtual std::string get_display_name() const override { return display_name(); }
66  virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(ParticleSystem)); }
67  virtual ObjectSettings get_settings() override;
68 
75  void set_enabled(bool enable);
81  bool get_enabled() const;
82 
83  int get_layer() const { return z_pos; }
84 
85 protected:
86  class Particle
87  {
88  public:
89  Particle() :
90  pos(0.0f, 0.0f),
91  angle(),
92  texture(),
93  alpha(),
94  scale(1.f) // This currently only works in the custom particle system
95  {}
96 
97  virtual ~Particle()
98  {}
99 
100  Vector pos;
101  // angle at which to draw particle
102  float angle;
103  SurfacePtr texture;
104  float alpha;
105  float scale; // see initializer
106 
107  private:
108  Particle(const Particle&) = delete;
109  Particle& operator=(const Particle&) = delete;
110  };
111 
112 protected:
113  float max_particle_size;
114  int z_pos;
115  std::vector<std::unique_ptr<Particle> > particles;
116  float virtual_width;
117  float virtual_height;
118 
123  bool enabled;
124 
125 private:
126  ParticleSystem(const ParticleSystem&) = delete;
127  ParticleSystem& operator=(const ParticleSystem&) = delete;
128 };
129 
130 #endif
131 
132 /* EOF */
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: particlesystem.cpp:80
bool enabled
Determines whether the system is enabled.
Definition: particlesystem.hpp:123
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user&#39;s locale.
Definition: particlesystem.hpp:65
Definition: particlesystem.hpp:86
Definition: object_settings.hpp:39
This is the base class for particle systems.
Definition: particlesystem.hpp:49
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
bool get_enabled() const
Definition: particlesystem.cpp:142
void set_enabled(bool enable)
Definition: particlesystem.cpp:136
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
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
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42