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