- beginnings of a wingling
[supertux.git] / src / particlesystem.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef SUPERTUX_PARTICLESYSTEM_H
21 #define SUPERTUX_PARTICLESYSTEM_H
22
23 #include <vector>
24 #include "texture.h"
25 #include "drawable.h"
26 #include "game_object.h"
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 rectangle 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, public Drawable
46 {
47 public:
48     ParticleSystem(DisplayManager& displaymanager);
49     virtual ~ParticleSystem();
50     
51     virtual void draw(Camera& view, int layer);
52
53 protected:
54     class Particle
55     {
56     public:
57         virtual ~Particle()
58         { }
59
60         float x, y;
61         int layer;
62         Surface* texture;
63     };
64     
65     std::vector<Particle*> particles;
66     float virtual_width, virtual_height;
67 };
68
69 class SnowParticleSystem : public ParticleSystem
70 {
71 public:
72     SnowParticleSystem(DisplayManager& displaymanager);
73     virtual ~SnowParticleSystem();
74
75     virtual void action(float elapsed_time);
76
77     std::string type() const
78     { return "SnowParticleSystem"; }
79     
80 private:
81     class SnowParticle : public Particle
82     {
83     public:
84         float speed;
85     };
86     
87     Surface* snowimages[3];
88 };
89
90 class CloudParticleSystem : public ParticleSystem
91 {
92 public:
93     CloudParticleSystem(DisplayManager& displaymanager);
94     virtual ~CloudParticleSystem();
95
96     virtual void action(float elapsed_time);
97
98     std::string type() const
99     { return "SnowParticleSystem"; }    
100     
101 private:
102     class CloudParticle : public Particle
103     {
104     public:
105         float speed;
106     };
107     
108     Surface* cloudimage;
109 };
110
111 #endif
112