More -Weffc++ cleanup, almost done
[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
69   float max_particle_size;
70   int z_pos;
71   std::vector<Particle*> particles;
72   float virtual_width;
73   float virtual_height;
74 };
75
76 class SnowParticleSystem : public ParticleSystem
77 {
78 public:
79   SnowParticleSystem();
80   virtual ~SnowParticleSystem();
81
82   void parse(const Reader& lisp);
83
84   virtual void update(float elapsed_time);
85
86   std::string type() const
87   { return "SnowParticleSystem"; }
88
89 private:
90   class SnowParticle : public Particle
91   {
92   public:
93     float speed;
94     float wobble;
95     float anchorx;
96     float drift_speed;
97
98     SnowParticle() :
99       speed(),
100       wobble(),
101       anchorx(),
102       drift_speed()
103     {}
104   };
105
106   Surface* snowimages[3];
107
108 private:
109   SnowParticleSystem(const SnowParticleSystem&);
110   SnowParticleSystem& operator=(const SnowParticleSystem&);
111 };
112
113 class GhostParticleSystem : public ParticleSystem
114 {
115 public:
116   GhostParticleSystem();
117   virtual ~GhostParticleSystem();
118
119   void parse(const Reader& lisp);
120   
121   virtual void update(float elapsed_time);
122
123   std::string type() const
124   { return "GhostParticleSystem"; }
125
126 private:
127   class GhostParticle : public Particle
128   {
129   public:
130     float speed;
131
132     GhostParticle() :
133       speed()
134     {}
135   };
136
137   Surface* ghosts[2];
138
139 private:
140   GhostParticleSystem(const GhostParticleSystem&);
141   GhostParticleSystem& operator=(const GhostParticleSystem&);
142 };
143
144 class CloudParticleSystem : public ParticleSystem
145 {
146 public:
147   CloudParticleSystem();
148   virtual ~CloudParticleSystem();
149
150   void parse(const Reader& lisp);
151   
152   virtual void update(float elapsed_time);
153
154   std::string type() const
155   { return "CloudParticleSystem"; }
156
157 private:
158   class CloudParticle : public Particle
159   {
160   public:
161     float speed;
162
163     CloudParticle() :
164       speed()
165     {}
166   };
167
168   Surface* cloudimage;
169
170 private:
171   CloudParticleSystem(const CloudParticleSystem&);
172   CloudParticleSystem& operator=(const CloudParticleSystem&);
173 };
174
175 #endif
176
177 /* EOF */