[cppcheck] Part 1: Performance
[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(Surface::create("images/objects/particles/cloud.png"))
28 {
29   virtual_width = 2000.0;
30
31   // create some random clouds
32   for(size_t i=0; i<15; ++i) {
33     CloudParticle* particle = new CloudParticle;
34     particle->pos.x = graphicsRandom.rand(static_cast<int>(virtual_width));
35     particle->pos.y = graphicsRandom.rand(static_cast<int>(virtual_height));
36     particle->texture = cloudimage;
37     particle->speed = -graphicsRandom.randf(25.0, 54.0);
38
39     particles.push_back(particle);
40   }
41 }
42
43 void
44 CloudParticleSystem::parse(const Reader& reader)
45 {
46   z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
47 }
48
49 CloudParticleSystem::~CloudParticleSystem()
50 {
51 }
52
53 void CloudParticleSystem::update(float elapsed_time)
54 {
55   std::vector<Particle*>::iterator i;
56   for(i = particles.begin(); i != particles.end(); ++i) {
57     CloudParticle* particle = (CloudParticle*) *i;
58     particle->pos.x += particle->speed * elapsed_time;
59   }
60 }
61
62 /* EOF */