00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #include "object/cloud_particle_system.hpp" 00018 00019 #include <math.h> 00020 00021 #include "math/random_generator.hpp" 00022 #include "supertux/globals.hpp" 00023 #include "video/drawing_context.hpp" 00024 00025 CloudParticleSystem::CloudParticleSystem() : 00026 ParticleSystem(128), 00027 cloudimage() 00028 { 00029 cloudimage = Surface::create("images/objects/particles/cloud.png"); 00030 00031 virtual_width = 2000.0; 00032 00033 // create some random clouds 00034 for(size_t i=0; i<15; ++i) { 00035 CloudParticle* particle = new CloudParticle; 00036 particle->pos.x = graphicsRandom.rand(static_cast<int>(virtual_width)); 00037 particle->pos.y = graphicsRandom.rand(static_cast<int>(virtual_height)); 00038 particle->texture = cloudimage; 00039 particle->speed = -graphicsRandom.randf(25.0, 54.0); 00040 00041 particles.push_back(particle); 00042 } 00043 } 00044 00045 void 00046 CloudParticleSystem::parse(const Reader& reader) 00047 { 00048 z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1); 00049 } 00050 00051 CloudParticleSystem::~CloudParticleSystem() 00052 { 00053 } 00054 00055 void CloudParticleSystem::update(float elapsed_time) 00056 { 00057 std::vector<Particle*>::iterator i; 00058 for(i = particles.begin(); i != particles.end(); ++i) { 00059 CloudParticle* particle = (CloudParticle*) *i; 00060 particle->pos.x += particle->speed * elapsed_time; 00061 } 00062 } 00063 00064 /* EOF */