More -Weffc++ cleanup
[supertux.git] / src / object / particlesystem_interactive.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_INTERACTIVE_HPP
18 #define HEADER_SUPERTUX_OBJECT_PARTICLESYSTEM_INTERACTIVE_HPP
19
20 #include "math/vector.hpp"
21 #include "supertux/game_object.hpp"
22 #include "supertux/sector.hpp"
23
24 class Surface;
25 class DisplayManager;
26
27 /**
28  * This is an alternative class for particle systems. It is responsible for storing a
29  * set of particles with each having an x- and y-coordinate the number of the
30  * layer where it should be drawn and a texture.
31  * This version of the particle system class doesn't use virtual screen coordinates,
32  * but Interactive ones. Particle systems which need Interactive levels coordinates, such
33  * as rain, should be implemented here.
34  * Classes that implement a particle system should subclass from this class,
35  * initialize particles in the constructor and move them in the simulate
36  * function.
37  */
38 class ParticleSystem_Interactive : public GameObject
39 {
40 public:
41   ParticleSystem_Interactive();
42   virtual ~ParticleSystem_Interactive();
43
44   virtual void draw(DrawingContext& context);
45
46 protected:
47   int z_pos;
48
49   class Particle
50   {
51   public:
52     Particle() : 
53       pos(), 
54       texture()
55     {}
56
57     virtual ~Particle()
58     {}
59
60     Vector pos;
61     Surface* texture;
62   };
63
64   std::vector<Particle*> particles;
65   float virtual_width, virtual_height;
66   int collision(Particle* particle, Vector movement);
67 };
68
69 class RainParticleSystem : public ParticleSystem_Interactive
70 {
71 public:
72   RainParticleSystem();
73   virtual ~RainParticleSystem();
74
75   void parse(const Reader& lisp);
76
77   virtual void update(float elapsed_time);
78
79   std::string type() const
80   { return "RainParticleSystem"; }
81
82 private:
83   class RainParticle : public Particle
84   {
85   public:
86     float speed;
87   };
88
89   Surface* rainimages[2];
90
91 private:
92   RainParticleSystem(const RainParticleSystem&);
93   RainParticleSystem& operator=(const RainParticleSystem&);
94 };
95
96 class CometParticleSystem : public ParticleSystem_Interactive
97 {
98 public:
99   CometParticleSystem();
100   virtual ~CometParticleSystem();
101
102   void parse(const Reader& lisp);
103   void write(lisp::Writer& writer);
104
105   virtual void update(float elapsed_time);
106
107   std::string type() const
108   { return "CometParticleSystem"; }
109
110 private:
111   class CometParticle : public Particle
112   {
113   public:
114     float speed;
115   };
116
117   Surface* cometimages[2];
118
119 private:
120   CometParticleSystem(const CometParticleSystem&);
121   CometParticleSystem& operator=(const CometParticleSystem&);
122 };
123
124 #endif
125
126 /* EOF */