src/object/particlesystem.cpp

Go to the documentation of this file.
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/particlesystem.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 ParticleSystem::ParticleSystem(float max_particle_size) :
00026   max_particle_size(max_particle_size),
00027   z_pos(),
00028   particles(),
00029   virtual_width(),
00030   virtual_height()
00031 {
00032   virtual_width = SCREEN_WIDTH + max_particle_size * 2;
00033   virtual_height = SCREEN_HEIGHT + max_particle_size *2;
00034   z_pos = LAYER_BACKGROUND1;
00035 }
00036 
00037 ParticleSystem::~ParticleSystem()
00038 {
00039   std::vector<Particle*>::iterator i;
00040   for(i = particles.begin(); i != particles.end(); ++i) {
00041     delete *i;
00042   }
00043 }
00044 
00045 void ParticleSystem::draw(DrawingContext& context)
00046 {
00047   float scrollx = context.get_translation().x;
00048   float scrolly = context.get_translation().y;
00049 
00050   context.push_transform();
00051   context.set_translation(Vector(max_particle_size,max_particle_size));
00052 
00053   std::vector<Particle*>::iterator i;
00054   for(i = particles.begin(); i != particles.end(); ++i) {
00055     Particle* particle = *i;
00056 
00057     // remap x,y coordinates onto screencoordinates
00058     Vector pos;
00059 
00060     pos.x = fmodf(particle->pos.x - scrollx, virtual_width);
00061     if(pos.x < 0) pos.x += virtual_width;
00062 
00063     pos.y = fmodf(particle->pos.y - scrolly, virtual_height);
00064     if(pos.y < 0) pos.y += virtual_height;
00065 
00066     //if(pos.x > virtual_width) pos.x -= virtual_width;
00067     //if(pos.y > virtual_height) pos.y -= virtual_height;
00068 
00069     context.draw_surface(particle->texture, pos, particle->angle, Color(1.0f, 1.0f, 1.0f), Blend(), z_pos);
00070   }
00071 
00072   context.pop_transform();
00073 }
00074 
00075 /* EOF */

Generated on Mon Jun 9 03:38:19 2014 for SuperTux by  doxygen 1.5.1