X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fparticles.cpp;h=36d3b6ef8652620fe3457e835e09d825141e1f4f;hb=7be55d4d3cfdeea2c68405c4b2a1999b8e246331;hp=910136b6b53738ffa3d4a7a63aa49db1d2113196;hpb=7bb247564b8236e60384827137e57f328f9614f5;p=supertux.git diff --git a/src/object/particles.cpp b/src/object/particles.cpp index 910136b6b..36d3b6ef8 100644 --- a/src/object/particles.cpp +++ b/src/object/particles.cpp @@ -24,14 +24,15 @@ #include "supertux/sector.hpp" #include "video/drawing_context.hpp" +//TODO: remove this function in favor of the one below Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, const Vector& initial_velocity, const Vector& acceleration, int number, Color color_, int size_, float life_time, int drawing_layer_) : - accel(acceleration), + accel(acceleration), timer(), live_forever(), - color(color_), - size(size_), + color(color_), + size(size_), drawing_layer(drawing_layer_), particles() { @@ -48,7 +49,7 @@ Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, Particle* particle = new Particle; particle->pos = epicenter; - float angle = systemRandom.rand(min_angle, max_angle) + float angle = graphicsRandom.rand(min_angle, max_angle) * (M_PI / 180); // convert to radius (radians?) particle->vel.x = /*fabs*/(sin(angle)) * initial_velocity.x; // if(angle >= M_PI && angle < M_PI*2) @@ -61,11 +62,49 @@ Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, } } +Particles::Particles(const Vector& epicenter, int min_angle, int max_angle, + const float min_initial_velocity, const float max_initial_velocity, + const Vector& acceleration, int number, Color color_, + int size_, float life_time, int drawing_layer_) : + + accel(acceleration), + timer(), + live_forever(), + color(color_), + size(size_), + drawing_layer(drawing_layer_), + particles() +{ + if(life_time == 0) { + live_forever = true; + } else { + live_forever = false; + timer.start(life_time); + } + + // create particles + for(int p = 0; p < number; p++) + { + Particle* particle = new Particle; + particle->pos = epicenter; + + float velocity = (min_initial_velocity == max_initial_velocity) ? min_initial_velocity : + graphicsRandom.rand(min_initial_velocity, max_initial_velocity); + float angle = (min_angle == max_angle) ? min_angle * (M_PI / 180) : + graphicsRandom.rand(min_angle, max_angle) * (M_PI / 180); // convert to radians + // Note that angle defined as clockwise from vertical (up is zero degrees, right is 90 degrees) + particle->vel.x = (sin(angle)) * velocity; + particle->vel.y = (-cos(angle)) * velocity; + + particles.push_back(particle); + } +} + Particles::~Particles() { // free particles for(std::vector::iterator i = particles.begin(); - i < particles.end(); i++) + i < particles.end(); ++i) delete (*i); } @@ -101,7 +140,7 @@ Particles::draw(DrawingContext& context) { // draw particles for(std::vector::iterator i = particles.begin(); - i != particles.end(); i++) { + i != particles.end(); ++i) { context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer); } }