src/object/comet_particle_system.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.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/comet_particle_system.hpp"
00018 
00019 #include "math/random_generator.hpp"
00020 #include "supertux/globals.hpp"
00021 #include "video/surface.hpp"
00022 #include "util/reader.hpp"
00023 
00024 CometParticleSystem::CometParticleSystem()
00025 {
00026   cometimages[0] = Surface::create("images/creatures/mr_bomb/exploding-left-0.png");
00027   cometimages[1] = Surface::create("images/creatures/mr_bomb/exploding-left-0.png");
00028 
00029   virtual_width = SCREEN_WIDTH * 2;
00030 
00031   // create some random comets
00032   size_t cometcount = 2;
00033   for(size_t i=0; i<cometcount; ++i) {
00034     CometParticle* particle = new CometParticle;
00035     particle->pos.x = graphicsRandom.rand(int(virtual_width));
00036     particle->pos.y = graphicsRandom.rand(int(virtual_height));
00037     int cometsize = graphicsRandom.rand(2);
00038     particle->texture = cometimages[cometsize];
00039     do {
00040       particle->speed = (cometsize+1)*30 + graphicsRandom.randf(3.6);
00041     } while(particle->speed < 1);
00042     particle->speed *= 10; // gravity
00043 
00044     particles.push_back(particle);
00045   }
00046 }
00047 
00048 void
00049 CometParticleSystem::parse(const Reader& reader)
00050 {
00051   z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
00052 }
00053 
00054 CometParticleSystem::~CometParticleSystem()
00055 {
00056 }
00057 
00058 void CometParticleSystem::update(float elapsed_time)
00059 {
00060   (void) elapsed_time;
00061 #if 0
00062   std::vector<Particle*>::iterator i;
00063   for(
00064     i = particles.begin(); i != particles.end(); ++i) {
00065     CometParticle* particle = (CometParticle*) *i;
00066     float movement = particle->speed * elapsed_time;
00067     float abs_x = Sector::current()->camera->get_translation().x;
00068     float abs_y = Sector::current()->camera->get_translation().y;
00069     particle->pos.y += movement;
00070     particle->pos.x -= movement;
00071     int col = collision(particle, Vector(-movement, movement));
00072     if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) {
00073       if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) {
00074         Sector::current()->add_object(new Bomb(particle->pos, LEFT));
00075       }
00076       int new_x = graphicsRandom.rand(int(virtual_width)) + int(abs_x);
00077       int new_y = 0;
00078       //FIXME: Don't move particles over solid tiles
00079       particle->pos.x = new_x;
00080       particle->pos.y = new_y;
00081     }
00082   }
00083 #endif
00084 }
00085 
00086 /* EOF */

Generated on Mon Apr 14 03:38:21 2014 for SuperTux by  doxygen 1.5.1