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