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/particlesystem.hpp"
21 #include "math/random_generator.hpp"
22 #include "supertux/globals.hpp"
23 #include "video/drawing_context.hpp"
25 ParticleSystem::ParticleSystem(float max_particle_size_) :
26 max_particle_size(max_particle_size_),
32 virtual_width = SCREEN_WIDTH + max_particle_size * 2;
33 virtual_height = SCREEN_HEIGHT + max_particle_size *2;
34 z_pos = LAYER_BACKGROUND1;
37 ParticleSystem::~ParticleSystem()
39 std::vector<Particle*>::iterator i;
40 for(i = particles.begin(); i != particles.end(); ++i) {
45 void ParticleSystem::draw(DrawingContext& context)
47 float scrollx = context.get_translation().x;
48 float scrolly = context.get_translation().y;
50 context.push_transform();
51 context.set_translation(Vector(max_particle_size,max_particle_size));
53 std::vector<Particle*>::iterator i;
54 for(i = particles.begin(); i != particles.end(); ++i) {
55 Particle* particle = *i;
57 // remap x,y coordinates onto screencoordinates
60 pos.x = fmodf(particle->pos.x - scrollx, virtual_width);
61 if(pos.x < 0) pos.x += virtual_width;
63 pos.y = fmodf(particle->pos.y - scrolly, virtual_height);
64 if(pos.y < 0) pos.y += virtual_height;
66 //if(pos.x > virtual_width) pos.x -= virtual_width;
67 //if(pos.y > virtual_height) pos.y -= virtual_height;
69 context.draw_surface(particle->texture, pos, particle->angle, Color(1.0f, 1.0f, 1.0f), Blend(), z_pos);
72 context.pop_transform();