More -Weffc++ cleanup, almost done
[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   class Particle
48   {
49   public:
50     Particle() : 
51       pos(), 
52       texture()
53     {}
54
55     virtual ~Particle()
56     {}
57
58     Vector pos;
59     Surface* texture;
60   };
61
62   int collision(Particle* particle, Vector movement);
63
64   int z_pos;
65   std::vector<Particle*> particles;
66   float virtual_width;
67   float virtual_height;
68 };
69
70 class RainParticleSystem : public ParticleSystem_Interactive
71 {
72 public:
73   RainParticleSystem();
74   virtual ~RainParticleSystem();
75
76   void parse(const Reader& lisp);
77
78   virtual void update(float elapsed_time);
79
80   std::string type() const
81   { return "RainParticleSystem"; }
82
83 private:
84   class RainParticle : public Particle
85   {
86   public:
87     float speed;
88
89     RainParticle() : 
90       speed()
91     {}
92   };
93
94   Surface* rainimages[2];
95
96 private:
97   RainParticleSystem(const RainParticleSystem&);
98   RainParticleSystem& operator=(const RainParticleSystem&);
99 };
100
101 class CometParticleSystem : public ParticleSystem_Interactive
102 {
103 public:
104   CometParticleSystem();
105   virtual ~CometParticleSystem();
106
107   void parse(const Reader& lisp);
108   void write(lisp::Writer& writer);
109
110   virtual void update(float elapsed_time);
111
112   std::string type() const
113   { return "CometParticleSystem"; }
114
115 private:
116   class CometParticle : public Particle
117   {
118   public:
119     float speed;
120
121     CometParticle() :
122       speed()
123     {}
124   };
125
126   Surface* cometimages[2];
127
128 private:
129   CometParticleSystem(const CometParticleSystem&);
130   CometParticleSystem& operator=(const CometParticleSystem&);
131 };
132
133 #endif
134
135 /* EOF */