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 "squirrel/exposed_object.hpp"
24 #include "scripting/particlesystem.hpp"
25 #include "supertux/game_object.hpp"
26 #include "video/surface_ptr.hpp"
27 
28 class ReaderMapping;
29 
46 class ParticleSystem : public GameObject,
47  public ExposedObject<ParticleSystem, scripting::ParticleSystem>
48 {
49 public:
50  ParticleSystem(const ReaderMapping& reader, float max_particle_size = 60);
51  ParticleSystem(float max_particle_size = 60);
52  virtual ~ParticleSystem();
53 
54  virtual void draw(DrawingContext& context) override;
55 
56  virtual std::string get_class() const override { return "particle-system"; }
57  virtual std::string get_display_name() const override { return _("Particle system"); }
58  virtual ObjectSettings get_settings() override;
59 
60  void set_enabled(bool enabled_);
61  bool get_enabled() const;
62 
63  int get_layer() const { return z_pos; }
64 
65 protected:
66  class Particle
67  {
68  public:
69  Particle() :
70  pos(),
71  angle(),
72  texture()
73  {}
74 
75  virtual ~Particle()
76  {}
77 
78  Vector pos;
79  // angle at which to draw particle
80  float angle;
81  SurfacePtr texture;
82 
83  private:
84  Particle(const Particle&) = delete;
85  Particle& operator=(const Particle&) = delete;
86  };
87 
88 protected:
89  float max_particle_size;
90  int z_pos;
91  std::vector<std::unique_ptr<Particle> > particles;
92  float virtual_width;
93  float virtual_height;
94  bool enabled;
95 
96 private:
97  ParticleSystem(const ParticleSystem&) = delete;
98  ParticleSystem& operator=(const ParticleSystem&) = delete;
99 };
100 
101 #endif
102 
103 /* EOF */
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: particlesystem.cpp:76
Simple two dimensional vector.
Definition: vector.hpp:24
This class binds a certain GameObject class to a scripting class.
Definition: exposed_object.hpp:45
Definition: particlesystem.hpp:66
Definition: object_settings.hpp:35
This is the base class for particle systems.
Definition: particlesystem.hpp:46
Base class for all the things that make up Levels&#39; Sectors.
Definition: game_object.hpp:46
Definition: reader_mapping.hpp:31
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42