3bb7313bf51db50115bcf1c5b88ced259224280a
[supertux.git] / src / object / particlesystem_interactive.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 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_INTERACTIVE_H
21 #define SUPERTUX_PARTICLESYSTEM_INTERACTIVE_H
22
23 #include <vector>
24
25 #include "video/surface.hpp"
26 #include "game_object.hpp"
27 #include "serializable.hpp"
28 #include "sector.hpp"
29 #include "math/vector.hpp"
30
31 namespace lisp {
32 class Lisp;
33 }
34
35 class DisplayManager;
36
37 /**
38  * This is an alternative 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  * This version of the particle system class doesn't use virtual screen coordinates,
42  * but Interactive ones. Particle systems which need Interactive levels coordinates, such
43  * as rain, should be implemented here.
44  * Classes that implement a particle system should subclass from this class,
45  * initialize particles in the constructor and move them in the simulate
46  * function.
47  */
48 class ParticleSystem_Interactive : public GameObject
49 {
50 public:
51     ParticleSystem_Interactive();
52     virtual ~ParticleSystem_Interactive();
53     
54     virtual void draw(DrawingContext& context);
55
56 protected:
57     int z_pos;
58
59     class Particle
60     {
61     public:
62         virtual ~Particle()
63         { }
64
65         Vector pos;
66         Surface* texture;
67     };
68     
69     std::vector<Particle*> particles;
70     float virtual_width, virtual_height;
71     int collision(Particle* particle, Vector movement);
72 };
73
74 class RainParticleSystem : public ParticleSystem_Interactive, public Serializable
75 {
76 public:
77     RainParticleSystem();
78     virtual ~RainParticleSystem();
79
80     void parse(const lisp::Lisp& lisp);
81     void write(lisp::Writer& writer);
82
83     virtual void update(float elapsed_time);
84
85     std::string type() const
86     { return "RainParticleSystem"; }
87     
88 private:
89     class RainParticle : public Particle
90     {
91     public:
92         float speed;
93     };
94     
95     Surface* rainimages[2];
96 };
97
98 class CometParticleSystem : public ParticleSystem_Interactive, public Serializable
99 {
100 public:
101     CometParticleSystem();
102     virtual ~CometParticleSystem();
103
104     void parse(const lisp::Lisp& lisp);
105     void write(lisp::Writer& writer);
106
107     virtual void update(float elapsed_time);
108
109     std::string type() const
110     { return "CometParticleSystem"; }
111     
112 private:
113     class CometParticle : public Particle
114     {
115     public:
116         float speed;
117     };
118     
119     Surface* cometimages[2];
120 };
121
122 #endif
123