0e72620f3b9f8b2a693351b6c5c8e84576ca8e39
[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 #include "video/surface_ptr.hpp"
26
27 class DisplayManager;
28
29 /**
30  * This is the base class for particle systems. It is responsible for storing a
31  * set of particles with each having an x- and y-coordinate the number of the
32  * layer where it should be drawn and a texture.
33  * The coordinate system used here is a virtual one. It would be a bad idea to
34  * populate whole levels with particles. So we're using a virtual rectangle
35  * here that is tiled onto the level when drawing. This rect.has the size
36  * (virtual_width, virtual_height). We're using modulo on the particle
37  * coordinates, so when a particle leaves left, it'll reenter at the right
38  * side.
39  *
40  * Classes that implement a particle system should subclass from this class,
41  * initialize particles in the constructor and move them in the simulate
42  * function.
43  */
44 class ParticleSystem : public GameObject
45 {
46 public:
47   ParticleSystem(float max_particle_size = 60);
48   virtual ~ParticleSystem();
49
50   virtual void draw(DrawingContext& context);
51
52 protected:
53   class Particle
54   {
55   public:
56     Particle() :
57       pos(),
58       texture()
59     {}
60    
61     virtual ~Particle()
62     {}
63
64     Vector pos;
65     SurfacePtr texture;
66
67   private:
68     Particle(const Particle&);
69     Particle& operator=(const Particle&);
70   };
71
72   float max_particle_size;
73   int z_pos;
74   std::vector<Particle*> particles;
75   float virtual_width;
76   float virtual_height;
77 };
78
79 #endif
80
81 /* EOF */