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