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.
19 #ifndef SUPERTUX_PARTICLESYSTEM_H
20 #define SUPERTUX_PARTICLESYSTEM_H
24 #include "video/surface.hpp"
25 #include "game_object.hpp"
26 #include "serializable.hpp"
28 #include "math/vector.hpp"
37 * This is the base class for particle systems. It is responsible for storing a
38 * set of particles with each having an x- and y-coordinate the number of the
39 * layer where it should be drawn and a texture.
40 * The coordinate system used here is a virtual one. It would be a bad idea to
41 * populate whole levels with particles. So we're using a virtual rectangle
42 * here that is tiled onto the level when drawing. This rect.has the size
43 * (virtual_width, virtual_height). We're using modulo on the particle
44 * coordinates, so when a particle leaves left, it'll reenter at the right
47 * Classes that implement a particle system should subclass from this class,
48 * initialize particles in the constructor and move them in the simulate
51 class ParticleSystem : public GameObject
55 virtual ~ParticleSystem();
57 virtual void draw(DrawingContext& context);
72 std::vector<Particle*> particles;
73 float virtual_width, virtual_height;
76 class SnowParticleSystem : public ParticleSystem, public Serializable
80 virtual ~SnowParticleSystem();
82 void parse(const lisp::Lisp& lisp);
83 void write(lisp::Writer& writer);
85 virtual void update(float elapsed_time);
87 std::string type() const
88 { return "SnowParticleSystem"; }
91 class SnowParticle : public Particle
97 Surface* snowimages[3];
100 class GhostParticleSystem : public ParticleSystem, public Serializable
103 GhostParticleSystem();
104 virtual ~GhostParticleSystem();
106 void parse(const lisp::Lisp& lisp);
107 void write(lisp::Writer& writer);
109 virtual void update(float elapsed_time);
111 std::string type() const
112 { return "GhostParticleSystem"; }
115 class GhostParticle : public Particle
124 class CloudParticleSystem : public ParticleSystem, public Serializable
127 CloudParticleSystem();
128 virtual ~CloudParticleSystem();
130 void parse(const lisp::Lisp& lisp);
131 void write(lisp::Writer& writer);
133 virtual void update(float elapsed_time);
135 std::string type() const
136 { return "SnowParticleSystem"; }
139 class CloudParticle : public Particle