4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de>
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.
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.
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.
20 #ifndef SUPERTUX_PARTICLESYSTEM_H
21 #define SUPERTUX_PARTICLESYSTEM_H
25 #include "video/surface.h"
26 #include "game_object.h"
27 #include "serializable.h"
29 using namespace SuperTux;
38 * This is the base class for particle systems. It is responsible for storing a
39 * set of particles with each having an x- and y-coordinate the number of the
40 * layer where it should be drawn and a texture.
41 * The coordinate system used here is a virtual one. It would be a bad idea to
42 * populate whole levels with particles. So we're using a virtual rectangle
43 * here that is tiled onto the level when drawing. This rectangle has the size
44 * (virtual_width, virtual_height). We're using modulo on the particle
45 * coordinates, so when a particle leaves left, it'll reenter at the right
48 * Classes that implement a particle system should subclass from this class,
49 * initialize particles in the constructor and move them in the simulate
52 class ParticleSystem : public GameObject
56 virtual ~ParticleSystem();
58 virtual void draw(DrawingContext& context);
73 std::vector<Particle*> particles;
74 float virtual_width, virtual_height;
77 class SnowParticleSystem : public ParticleSystem, public Serializable
81 virtual ~SnowParticleSystem();
83 void parse(const lisp::Lisp& lisp);
84 void write(lisp::Writer& writer);
86 virtual void action(float elapsed_time);
88 std::string type() const
89 { return "SnowParticleSystem"; }
92 class SnowParticle : public Particle
98 Surface* snowimages[3];
101 class RainParticleSystem : public ParticleSystem, public Serializable
104 RainParticleSystem();
105 virtual ~RainParticleSystem();
107 void parse(const lisp::Lisp& lisp);
108 void write(lisp::Writer& writer);
110 virtual void action(float elapsed_time);
112 std::string type() const
113 { return "RainParticleSystem"; }
116 class RainParticle : public Particle
122 Surface* rainimages[2];
125 class CloudParticleSystem : public ParticleSystem, public Serializable
128 CloudParticleSystem();
129 virtual ~CloudParticleSystem();
131 void parse(const lisp::Lisp& lisp);
132 void write(lisp::Writer& writer);
134 virtual void action(float elapsed_time);
136 std::string type() const
137 { return "SnowParticleSystem"; }
140 class CloudParticle : public Particle