00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
00067
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