2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #include "object/cloud_particle_system.hpp"
21 #include "math/random_generator.hpp"
22 #include "supertux/globals.hpp"
23 #include "video/drawing_context.hpp"
25 CloudParticleSystem::CloudParticleSystem() :
27 cloudimage(Surface::create("images/objects/particles/cloud.png"))
29 virtual_width = 2000.0;
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);
39 particles.push_back(particle);
44 CloudParticleSystem::parse(const Reader& reader)
46 z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
49 CloudParticleSystem::~CloudParticleSystem()
53 void CloudParticleSystem::update(float elapsed_time)
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;