*** empty log message ***
[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 #ifndef SUPERTUX_PARTICLESYSTEM_H
20 #define SUPERTUX_PARTICLESYSTEM_H
21
22 #include <vector>
23 #include "texture.h"
24
25 /**
26  * This is the base class for particle systems. It is responsible for storing a
27  * set of particles with each having an x- and y-coordinate the number of the
28  * layer where it should be drawn and a texture.
29  * The coordinate system used here is a virtual one. It would be a bad idea to
30  * populate whole levels with particles. So we're using a virtual rectangle
31  * here that is tiled onto the level when drawing. This rectangle has the size
32  * (virtual_width, virtual_height). We're using modulo on the particle
33  * coordinates, so when a particle leaves left, it'll reenter at the right
34  * side.
35  *
36  * Classes that implement a particle system should subclass from this class,
37  * initialize particles in the constructor and move them in the simulate
38  * function.
39  */
40 class ParticleSystem
41 {
42 public:
43     ParticleSystem();
44     virtual ~ParticleSystem();
45     
46     void draw(float scrollx, float scrolly, int layer);
47
48     virtual void simulate(float elapsed_time) = 0;
49
50 protected:
51     class Particle
52     {
53     public:
54         virtual ~Particle()
55         { }
56
57         float x, y;
58         int layer;
59         texture_type* texture;
60     };
61     
62     std::vector<Particle*> particles;
63     float virtual_width, virtual_height;
64 };
65
66 class SnowParticleSystem : public ParticleSystem
67 {
68 public:
69     SnowParticleSystem();
70     virtual ~SnowParticleSystem();
71
72     virtual void simulate(float elapsed_time);
73     
74 private:
75     class SnowParticle : public Particle
76     {
77     public:
78         float speed;
79     };
80     
81     texture_type snowimages[3];
82 };
83
84 class CloudParticleSystem : public ParticleSystem
85 {
86 public:
87     CloudParticleSystem();
88     virtual ~CloudParticleSystem();
89
90     virtual void simulate(float elapsed_time);
91     
92 private:
93     class CloudParticle : public Particle
94     {
95     public:
96         float speed;
97     };
98     
99     texture_type cloudimage;
100 };
101
102 #endif
103