X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fparticlesystem.cpp;h=8df8108697174dba87538e574ad0deae3679505d;hb=2e163cb10e0a6af504275585e7c31091931dd7b2;hp=bb79f54de91603d3f1fd6e4f15930f0987f2b80b;hpb=c1277f5b7db9f55d1d28f658b4e804f32b76f0ce;p=supertux.git diff --git a/src/object/particlesystem.cpp b/src/object/particlesystem.cpp index bb79f54de..8df810869 100644 --- a/src/object/particlesystem.cpp +++ b/src/object/particlesystem.cpp @@ -16,14 +16,18 @@ #include "object/particlesystem.hpp" -#include +#include #include "math/random_generator.hpp" -#include "supertux/main.hpp" +#include "supertux/globals.hpp" #include "video/drawing_context.hpp" -ParticleSystem::ParticleSystem(float max_particle_size) : - max_particle_size(max_particle_size) +ParticleSystem::ParticleSystem(float max_particle_size_) : + max_particle_size(max_particle_size_), + z_pos(), + particles(), + virtual_width(), + virtual_height() { virtual_width = SCREEN_WIDTH + max_particle_size * 2; virtual_height = SCREEN_HEIGHT + max_particle_size *2; @@ -62,156 +66,10 @@ void ParticleSystem::draw(DrawingContext& context) //if(pos.x > virtual_width) pos.x -= virtual_width; //if(pos.y > virtual_height) pos.y -= virtual_height; - context.draw_surface(particle->texture, pos, z_pos); + context.draw_surface(particle->texture, pos, particle->angle, Color(1.0f, 1.0f, 1.0f), Blend(), z_pos); } context.pop_transform(); } -SnowParticleSystem::SnowParticleSystem() -{ - snowimages[0] = new Surface("images/objects/particles/snow2.png"); - snowimages[1] = new Surface("images/objects/particles/snow1.png"); - snowimages[2] = new Surface("images/objects/particles/snow0.png"); - - virtual_width = SCREEN_WIDTH * 2; - - // create some random snowflakes - size_t snowflakecount = size_t(virtual_width/10.0); - for(size_t i=0; ipos.x = systemRandom.randf(virtual_width); - particle->pos.y = systemRandom.randf(SCREEN_HEIGHT); - particle->anchorx = particle->pos.x + (systemRandom.randf(-0.5, 0.5) * 16); - particle->drift_speed = systemRandom.randf(-0.5, 0.5) * 0.3; - particle->wobble = 0.0; - - particle->texture = snowimages[snowsize]; - - particle->speed = 1 + (2 - snowsize)/2 + systemRandom.randf(1.8); - particle->speed *= 20; // gravity - - particles.push_back(particle); - } -} - -void -SnowParticleSystem::parse(const Reader& reader) -{ - reader.get("z-pos", z_pos); -} - -SnowParticleSystem::~SnowParticleSystem() -{ - for(int i=0;i<3;++i) - delete snowimages[i]; -} - -void SnowParticleSystem::update(float elapsed_time) -{ - std::vector::iterator i; - - for(i = particles.begin(); i != particles.end(); ++i) { - SnowParticle* particle = (SnowParticle*) *i; - float anchor_delta; - - particle->pos.y += particle->speed * elapsed_time; - particle->pos.x += particle->wobble * elapsed_time /* * particle->speed * 0.125*/; - - anchor_delta = (particle->anchorx - particle->pos.x); - particle->wobble += (4 * anchor_delta * 0.05) + systemRandom.randf(-0.5, 0.5); - particle->wobble *= 0.99f; - particle->anchorx += particle->drift_speed * elapsed_time; - } -} - -//FIXME: Sometimes both ghosts have the same image -// Ghosts don't change their movement pattern - not random -GhostParticleSystem::GhostParticleSystem() -{ - ghosts[0] = new Surface("images/objects/particles/ghost0.png"); - ghosts[1] = new Surface("images/objects/particles/ghost1.png"); - - virtual_width = SCREEN_WIDTH * 2; - - // create two ghosts - size_t ghostcount = 2; - for(size_t i=0; ipos.x = systemRandom.randf(virtual_width); - particle->pos.y = systemRandom.randf(SCREEN_HEIGHT); - int size = systemRandom.rand(2); - particle->texture = ghosts[size]; - particle->speed = systemRandom.randf(std::max(50, (size * 10)), 180 + (size * 10)); - particles.push_back(particle); - } -} - -void -GhostParticleSystem::parse(const Reader& reader) -{ - reader.get("z-pos", z_pos); -} - -GhostParticleSystem::~GhostParticleSystem() -{ - for(int i=0;i<2;++i) - delete ghosts[i]; -} - -void GhostParticleSystem::update(float elapsed_time) -{ - std::vector::iterator i; - for(i = particles.begin(); i != particles.end(); ++i) { - GhostParticle* particle = (GhostParticle*) *i; - particle->pos.y -= particle->speed * elapsed_time; - particle->pos.x -= particle->speed * elapsed_time; - if(particle->pos.y > SCREEN_HEIGHT) { - particle->pos.y = fmodf(particle->pos.y , virtual_height); - particle->pos.x = systemRandom.rand(static_cast(virtual_width)); - } - } -} - -CloudParticleSystem::CloudParticleSystem() : - ParticleSystem(128) -{ - cloudimage = new Surface("images/objects/particles/cloud.png"); - - virtual_width = 2000.0; - - // create some random clouds - for(size_t i=0; i<15; ++i) { - CloudParticle* particle = new CloudParticle; - particle->pos.x = systemRandom.rand(static_cast(virtual_width)); - particle->pos.y = systemRandom.rand(static_cast(virtual_height)); - particle->texture = cloudimage; - particle->speed = -systemRandom.randf(25.0, 54.0); - - particles.push_back(particle); - } -} - -void -CloudParticleSystem::parse(const Reader& reader) -{ - reader.get("z-pos", z_pos); -} - -CloudParticleSystem::~CloudParticleSystem() -{ - delete cloudimage; -} - -void CloudParticleSystem::update(float elapsed_time) -{ - std::vector::iterator i; - for(i = particles.begin(); i != particles.end(); ++i) { - CloudParticle* particle = (CloudParticle*) *i; - particle->pos.x += particle->speed * elapsed_time; - } -} - /* EOF */