- Made miniswig support HSQUIRRELVM arguments (and realized it was not needed
[supertux.git] / src / object / 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 #ifndef SUPERTUX_PARTICLESYSTEM_H
20 #define SUPERTUX_PARTICLESYSTEM_H
21
22 #include <vector>
23
24 #include "video/surface.h"
25 #include "game_object.h"
26 #include "serializable.h"
27
28 namespace lisp {
29 class Lisp;
30 }
31
32 class DisplayManager;
33
34 /**
35  * This is the base class for particle systems. It is responsible for storing a
36  * set of particles with each having an x- and y-coordinate the number of the
37  * layer where it should be drawn and a texture.
38  * The coordinate system used here is a virtual one. It would be a bad idea to
39  * populate whole levels with particles. So we're using a virtual rectangle
40  * here that is tiled onto the level when drawing. This rect.has the size
41  * (virtual_width, virtual_height). We're using modulo on the particle
42  * coordinates, so when a particle leaves left, it'll reenter at the right
43  * side.
44  *
45  * Classes that implement a particle system should subclass from this class,
46  * initialize particles in the constructor and move them in the simulate
47  * function.
48  */
49 class ParticleSystem : public GameObject
50 {
51 public:
52     ParticleSystem();
53     virtual ~ParticleSystem();
54     
55     virtual void draw(DrawingContext& context);
56
57 protected:
58     int layer;
59
60     class Particle
61     {
62     public:
63         virtual ~Particle()
64         { }
65
66         Vector pos;
67         Surface* texture;
68     };
69     
70     std::vector<Particle*> particles;
71     float virtual_width, virtual_height;
72 };
73
74 class SnowParticleSystem : public ParticleSystem, public Serializable
75 {
76 public:
77     SnowParticleSystem();
78     virtual ~SnowParticleSystem();
79
80     void parse(const lisp::Lisp& lisp);
81     void write(lisp::Writer& writer);
82
83     virtual void action(float elapsed_time);
84
85     std::string type() const
86     { return "SnowParticleSystem"; }
87     
88 private:
89     class SnowParticle : public Particle
90     {
91     public:
92         float speed;
93     };
94     
95     Surface* snowimages[3];
96 };
97
98 class RainParticleSystem : public ParticleSystem, public Serializable
99 {
100 public:
101     RainParticleSystem();
102     virtual ~RainParticleSystem();
103
104     void parse(const lisp::Lisp& lisp);
105     void write(lisp::Writer& writer);
106
107     virtual void action(float elapsed_time);
108
109     std::string type() const
110     { return "RainParticleSystem"; }
111     
112 private:
113     class RainParticle : public Particle
114     {
115     public:
116         float speed;
117     };
118     
119     Surface* rainimages[2];
120 };
121
122 class CloudParticleSystem : public ParticleSystem, public Serializable
123 {
124 public:
125     CloudParticleSystem();
126     virtual ~CloudParticleSystem();
127
128     void parse(const lisp::Lisp& lisp);
129     void write(lisp::Writer& writer);
130
131     virtual void action(float elapsed_time);
132
133     std::string type() const
134     { return "SnowParticleSystem"; }    
135     
136 private:
137     class CloudParticle : public Particle
138     {
139     public:
140         float speed;
141     };
142     
143     Surface* cloudimage;
144 };
145
146 #endif
147