From: Marek Moeckel Date: Sun, 15 May 2005 10:06:37 +0000 (+0000) Subject: more work on rain X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=794d19cbaa7b40a3ee378a447a646a2d70e8ac7a;p=supertux.git more work on rain SVN-Revision: 2488 --- diff --git a/src/object/particlesystem_absolute.cpp b/src/object/particlesystem_absolute.cpp index 95e1ae539..e3713cb72 100644 --- a/src/object/particlesystem_absolute.cpp +++ b/src/object/particlesystem_absolute.cpp @@ -36,15 +36,14 @@ #include "collision_hit.h" #include "object/camera.h" -//TODO: Try to equally distribute rain throughout the level -// Dynamically create splashes at collision spots -// Check why it can rain through boxes +//TODO: Dynamically create splashes at collision spots +// Find a way to make rain collide with objects like bonus blocks // Add an option to set rain strength ParticleSystem_Absolute::ParticleSystem_Absolute() { virtual_width = SCREEN_WIDTH; virtual_height = SCREEN_HEIGHT; - layer = LAYER_BACKGROUND1; + layer = LAYER_TILES; } ParticleSystem_Absolute::~ParticleSystem_Absolute() @@ -57,25 +56,11 @@ ParticleSystem_Absolute::~ParticleSystem_Absolute() void ParticleSystem_Absolute::draw(DrawingContext& context) { - //float scrollx = context.get_translation().x; - //float scrolly = context.get_translation().y; - context.push_transform(); - //context.set_translation(Vector(0,0)); std::vector::iterator i; for(i = particles.begin(); i != particles.end(); ++i) { Particle* particle = *i; - - // remap x,y coordinates onto screencoordinates - /*Vector pos; - pos.x = fmodf(particle->pos.x - scrollx, virtual_width); - if(pos.x < 0) pos.x += virtual_width; - pos.y = fmodf(particle->pos.y - scrolly, virtual_height); - if(pos.y < 0) pos.y += virtual_height; - - if(pos.x > SCREEN_WIDTH) pos.x -= virtual_width; - if(pos.y > SCREEN_HEIGHT) pos.y -= virtual_height;*/ context.draw_surface(particle->texture, particle->pos, layer); } @@ -90,7 +75,7 @@ RainParticleSystem::RainParticleSystem() virtual_width = SCREEN_WIDTH * 2; // create some random raindrops - size_t raindropcount = size_t(virtual_width/4.0); + size_t raindropcount = size_t(virtual_width/6.0); for(size_t i=0; ipos.x = rand() % int(virtual_width); @@ -138,8 +123,11 @@ void RainParticleSystem::update(float elapsed_time) particle->pos.y += movement; particle->pos.x -= movement; if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (collision(particle, Vector(-movement, movement)))) { - particle->pos.y = 0; - particle->pos.x = rand() % int(abs_x + virtual_width); + int new_x = (rand() % int(virtual_width)) + int(abs_x); + int new_y = 0; + //FIXME: Don't move particles over solid tiles + particle->pos.x = new_x; + particle->pos.y = new_y; } } } @@ -169,7 +157,6 @@ RainParticleSystem::collision(RainParticle* object, Vector movement) for(int x = starttilex; x*32 < max_x; ++x) { for(int y = starttiley; y*32 < max_y; ++y) { const Tile* tile = solids->get_tile(x, y); - //std::cout << "Tile at: " << x << "," << y << std::endl; if(!tile) continue; // skip non-solid tiles diff --git a/src/object/particlesystem_absolute.h b/src/object/particlesystem_absolute.h index 1a3d13755..0db25986a 100644 --- a/src/object/particlesystem_absolute.h +++ b/src/object/particlesystem_absolute.h @@ -34,16 +34,12 @@ class Lisp; class DisplayManager; /** - * This is the base class for particle systems. It is responsible for storing a + * This is an alternative class for particle systems. It is responsible for storing a * set of particles with each having an x- and y-coordinate the number of the * layer where it should be drawn and a texture. - * The coordinate system used here is a virtual one. It would be a bad idea to - * populate whole levels with particles. So we're using a virtual rectangle - * here that is tiled onto the level when drawing. This rect.has the size - * (virtual_width, virtual_height). We're using modulo on the particle - * coordinates, so when a particle leaves left, it'll reenter at the right - * side. - * + * This version of the particle system class doesn't use virtual screen coordinates, + * but absolute ones. Particle systems which need absolute levels coordinates, such + * as rain, should be implemented here. * Classes that implement a particle system should subclass from this class, * initialize particles in the constructor and move them in the simulate * function.