big refactoring of level and world class. A level is now basically a set of
[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 "screen/texture.h"
25 #include "game_object.h"
26 #include "serializable.h"
27
28 class LispReader;
29 class DisplayManager;
30
31 /**
32  * This is the base class for particle systems. It is responsible for storing a
33  * set of particles with each having an x- and y-coordinate the number of the
34  * layer where it should be drawn and a texture.
35  * The coordinate system used here is a virtual one. It would be a bad idea to
36  * populate whole levels with particles. So we're using a virtual rectangle
37  * here that is tiled onto the level when drawing. This rectangle has the size
38  * (virtual_width, virtual_height). We're using modulo on the particle
39  * coordinates, so when a particle leaves left, it'll reenter at the right
40  * side.
41  *
42  * Classes that implement a particle system should subclass from this class,
43  * initialize particles in the constructor and move them in the simulate
44  * function.
45  */
46 class ParticleSystem : public GameObject
47 {
48 public:
49     ParticleSystem();
50     virtual ~ParticleSystem();
51     
52     virtual void draw(DrawingContext& context);
53
54 protected:
55     int layer;
56
57     class Particle
58     {
59     public:
60         virtual ~Particle()
61         { }
62
63         Vector pos;
64         Surface* texture;
65     };
66     
67     std::vector<Particle*> particles;
68     float virtual_width, virtual_height;
69 };
70
71 class SnowParticleSystem : public ParticleSystem, public Serializable
72 {
73 public:
74     SnowParticleSystem();
75     virtual ~SnowParticleSystem();
76
77     void parse(LispReader& reader);
78     void write(LispWriter& writer);
79
80     virtual void action(float elapsed_time);
81
82     std::string type() const
83     { return "SnowParticleSystem"; }
84     
85 private:
86     class SnowParticle : public Particle
87     {
88     public:
89         float speed;
90     };
91     
92     Surface* snowimages[3];
93 };
94
95 class CloudParticleSystem : public ParticleSystem, public Serializable
96 {
97 public:
98     CloudParticleSystem();
99     virtual ~CloudParticleSystem();
100
101     void parse(LispReader& reader);
102     void write(LispWriter& writer);
103
104     virtual void action(float elapsed_time);
105
106     std::string type() const
107     { return "SnowParticleSystem"; }    
108     
109 private:
110     class CloudParticle : public Particle
111     {
112     public:
113         float speed;
114     };
115     
116     Surface* cloudimage;
117 };
118
119 #endif
120