Finished -Weffc++ cleanup
[supertux.git] / src / object / 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 "util/reader.hpp"
25
26 class Surface;
27
28 class DisplayManager;
29
30 /**
31  * This is the base class for particle systems. It is responsible for storing a
32  * set of particles with each having an x- and y-coordinate the number of the
33  * layer where it should be drawn and a texture.
34  * The coordinate system used here is a virtual one. It would be a bad idea to
35  * populate whole levels with particles. So we're using a virtual rectangle
36  * here that is tiled onto the level when drawing. This rect.has the size
37  * (virtual_width, virtual_height). We're using modulo on the particle
38  * coordinates, so when a particle leaves left, it'll reenter at the right
39  * side.
40  *
41  * Classes that implement a particle system should subclass from this class,
42  * initialize particles in the constructor and move them in the simulate
43  * function.
44  */
45 class ParticleSystem : public GameObject
46 {
47 public:
48   ParticleSystem(float max_particle_size = 60);
49   virtual ~ParticleSystem();
50
51   virtual void draw(DrawingContext& context);
52
53 protected:
54   class Particle
55   {
56   public:
57     Particle() :
58       pos(),
59       texture()
60     {}
61    
62     virtual ~Particle()
63     {}
64
65     Vector pos;
66     Surface* texture;
67
68   private:
69     Particle(const Particle&);
70     Particle& operator=(const Particle&);
71   };
72
73   float max_particle_size;
74   int z_pos;
75   std::vector<Particle*> particles;
76   float virtual_width;
77   float virtual_height;
78 };
79
80 class SnowParticleSystem : public ParticleSystem
81 {
82 public:
83   SnowParticleSystem();
84   virtual ~SnowParticleSystem();
85
86   void parse(const Reader& lisp);
87
88   virtual void update(float elapsed_time);
89
90   std::string type() const
91   { return "SnowParticleSystem"; }
92
93 private:
94   class SnowParticle : public Particle
95   {
96   public:
97     float speed;
98     float wobble;
99     float anchorx;
100     float drift_speed;
101
102     SnowParticle() :
103       speed(),
104       wobble(),
105       anchorx(),
106       drift_speed()
107     {}
108   };
109
110   Surface* snowimages[3];
111
112 private:
113   SnowParticleSystem(const SnowParticleSystem&);
114   SnowParticleSystem& operator=(const SnowParticleSystem&);
115 };
116
117 class GhostParticleSystem : public ParticleSystem
118 {
119 public:
120   GhostParticleSystem();
121   virtual ~GhostParticleSystem();
122
123   void parse(const Reader& lisp);
124   
125   virtual void update(float elapsed_time);
126
127   std::string type() const
128   { return "GhostParticleSystem"; }
129
130 private:
131   class GhostParticle : public Particle
132   {
133   public:
134     float speed;
135
136     GhostParticle() :
137       speed()
138     {}
139   };
140
141   Surface* ghosts[2];
142
143 private:
144   GhostParticleSystem(const GhostParticleSystem&);
145   GhostParticleSystem& operator=(const GhostParticleSystem&);
146 };
147
148 class CloudParticleSystem : public ParticleSystem
149 {
150 public:
151   CloudParticleSystem();
152   virtual ~CloudParticleSystem();
153
154   void parse(const Reader& lisp);
155   
156   virtual void update(float elapsed_time);
157
158   std::string type() const
159   { return "CloudParticleSystem"; }
160
161 private:
162   class CloudParticle : public Particle
163   {
164   public:
165     float speed;
166
167     CloudParticle() :
168       speed()
169     {}
170   };
171
172   Surface* cloudimage;
173
174 private:
175   CloudParticleSystem(const CloudParticleSystem&);
176   CloudParticleSystem& operator=(const CloudParticleSystem&);
177 };
178
179 #endif
180
181 /* EOF */