From 3d65f0e17010d927262aa354f8da9bc0ebc1a487 Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Sat, 18 Jun 2005 10:01:32 +0000 Subject: [PATCH] fixed rain splashes SVN-Revision: 2618 --- src/object/particlesystem_interactive.cpp | 34 +++++++++++++++++++------------ src/object/particlesystem_interactive.h | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/object/particlesystem_interactive.cpp b/src/object/particlesystem_interactive.cpp index d411f8921..69c75243f 100644 --- a/src/object/particlesystem_interactive.cpp +++ b/src/object/particlesystem_interactive.cpp @@ -69,7 +69,7 @@ void ParticleSystem_Interactive::draw(DrawingContext& context) context.pop_transform(); } -bool +int ParticleSystem_Interactive::collision(Particle* object, Vector movement) { TileMap* solids = Sector::current()->solids; @@ -123,8 +123,14 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) } // did we collide at all? - if(hit.time < 0) - return false; else return true; + if(hit.time < 0) { + return -1; //no collision + } + else { + if ((hit.normal.x == 1) && (hit.normal.y == 0)) + return 1; //collision from right + else return 0; //collision from above + } } RainParticleSystem::RainParticleSystem() @@ -182,21 +188,23 @@ void RainParticleSystem::update(float elapsed_time) float abs_y = Sector::current()->camera->get_translation().y; particle->pos.y += movement; particle->pos.x -= movement; - if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (collision(particle, Vector(-movement, movement)))) { + int col = collision(particle, Vector(-movement, movement)); + if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { //Create rainsplash if (particle->pos.y <= SCREEN_HEIGHT + abs_y){ - //TODO: Find out at which side of the tile the collision happens - bool vertical = false; + bool vertical = (col == 1); int splash_x, splash_y; - if (vertical) { - splash_x = int(particle->pos.x) - (int(particle->pos.x) % 32) + 32; - splash_y = int(particle->pos.y); - } - else { + if (!vertical) { //check if collision happened from above splash_x = int(particle->pos.x); splash_y = int(particle->pos.y) - (int(particle->pos.y) % 32) + 32; + Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); } - Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); + // Uncomment the following to display vertical splashes, too + /* else { + splash_x = int(particle->pos.x) - (int(particle->pos.x) % 32) + 32; + splash_y = int(particle->pos.y); + Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical)); + } */ } int new_x = (rand() % int(virtual_width)) + int(abs_x); int new_y = 0; @@ -262,7 +270,7 @@ void CometParticleSystem::update(float elapsed_time) float abs_y = Sector::current()->camera->get_translation().y; particle->pos.y += movement; particle->pos.x -= movement; - if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (collision(particle, Vector(-movement, movement)))) { + if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (collision(particle, Vector(-movement, movement)) >= 0)) { if (particle->pos.y <= SCREEN_HEIGHT + abs_y) { Sector::current()->add_object(new Bomb(particle->pos, LEFT)); } diff --git a/src/object/particlesystem_interactive.h b/src/object/particlesystem_interactive.h index c214fa32e..edbae31a6 100644 --- a/src/object/particlesystem_interactive.h +++ b/src/object/particlesystem_interactive.h @@ -67,7 +67,7 @@ protected: std::vector particles; float virtual_width, virtual_height; - bool collision(Particle* particle, Vector movement); + int collision(Particle* particle, Vector movement); }; class RainParticleSystem : public ParticleSystem_Interactive, public Serializable -- 2.11.0