ace29eecaac5fa6968491a11c4c23b06138035b3
[supertux.git] / src / object / cloud_particle_system.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "object/cloud_particle_system.hpp"
18
19 #include <math.h>
20
21 #include "math/random_generator.hpp"
22 #include "supertux/globals.hpp"
23 #include "video/drawing_context.hpp"
24
25 CloudParticleSystem::CloudParticleSystem() :
26   ParticleSystem(128),
27   cloudimage()
28 {
29   cloudimage = Surface::create("images/objects/particles/cloud.png");
30
31   virtual_width = 2000.0;
32
33   // create some random clouds
34   for(size_t i=0; i<15; ++i) {
35     CloudParticle* particle = new CloudParticle;
36     particle->pos.x = systemRandom.rand(static_cast<int>(virtual_width));
37     particle->pos.y = systemRandom.rand(static_cast<int>(virtual_height));
38     particle->texture = cloudimage;
39     particle->speed = -systemRandom.randf(25.0, 54.0);
40
41     particles.push_back(particle);
42   }
43 }
44
45 void
46 CloudParticleSystem::parse(const Reader& reader)
47 {
48   reader.get("z-pos", z_pos);
49 }
50
51 CloudParticleSystem::~CloudParticleSystem()
52 {
53 }
54
55 void CloudParticleSystem::update(float elapsed_time)
56 {
57   std::vector<Particle*>::iterator i;
58   for(i = particles.begin(); i != particles.end(); ++i) {
59     CloudParticle* particle = (CloudParticle*) *i;
60     particle->pos.x += particle->speed * elapsed_time;
61   }
62 }
63
64 /* EOF */