X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fparticlesystem_interactive.cpp;h=0a9228abc4a078aca837ecaeb552c73de75dd18b;hb=5f1c84ed5ce0ab5450f92082a9aaaa9ca0effc39;hp=13064bcc3898f78175d6a841af1a3041c6851ef2;hpb=e5593e0f4b262cb13d8edd4f2b16f9b16eca4e16;p=supertux.git diff --git a/src/object/particlesystem_interactive.cpp b/src/object/particlesystem_interactive.cpp index 13064bcc3..0a9228abc 100644 --- a/src/object/particlesystem_interactive.cpp +++ b/src/object/particlesystem_interactive.cpp @@ -1,7 +1,7 @@ -// $Id: particlesystem.cpp 2470 2005-05-11 14:49:28Z wansti $ -// +// $Id$ +// // SuperTux -// Copyright (C) 2004 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,40 +12,42 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include #include -#include "particlesystem_interactive.h" -#include "video/drawing_context.h" -#include "lisp/parser.h" -#include "lisp/lisp.h" -#include "lisp/writer.h" -#include "resources.h" -#include "main.h" +#include "particlesystem_interactive.hpp" +#include "video/drawing_context.hpp" +#include "lisp/parser.hpp" +#include "lisp/lisp.hpp" +#include "lisp/writer.hpp" +#include "resources.hpp" +#include "main.hpp" -#include "tile.h" -#include "tilemap.h" -#include "math/aatriangle.h" -#include "collision.h" -#include "collision_hit.h" -#include "object/camera.h" -#include "object/rainsplash.h" -#include "badguy/bomb.h" +#include "tile.hpp" +#include "tilemap.hpp" +#include "math/aatriangle.hpp" +#include "collision.hpp" +#include "collision_hit.hpp" +#include "object/camera.hpp" +#include "object/rainsplash.hpp" +#include "badguy/bomb.hpp" +#include "random_generator.hpp" -//TODO: Dynamically create splashes at collision spots -// Find a way to make rain collide with objects like bonus blocks +//TODO: Find a way to make rain collide with objects like bonus blocks // Add an option to set rain strength +// Fix rain being "respawned" over solid tiles ParticleSystem_Interactive::ParticleSystem_Interactive() { virtual_width = SCREEN_WIDTH; virtual_height = SCREEN_HEIGHT; - layer = LAYER_TILES; + z_pos = 0; } ParticleSystem_Interactive::~ParticleSystem_Interactive() @@ -63,13 +65,13 @@ void ParticleSystem_Interactive::draw(DrawingContext& context) std::vector::iterator i; for(i = particles.begin(); i != particles.end(); ++i) { Particle* particle = *i; - context.draw_surface(particle->texture, particle->pos, layer); + context.draw_surface(particle->texture, particle->pos, z_pos); } context.pop_transform(); } -bool +int ParticleSystem_Interactive::collision(Particle* object, Vector movement) { TileMap* solids = Sector::current()->solids; @@ -80,6 +82,7 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) x2 = x1 + 32 + movement.x; y1 = object->pos.y; y2 = y1 + 32 + movement.y; + bool water = false; // test with all tiles in this rectangle int starttilex = int(x1-1) / 32; @@ -96,8 +99,10 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) const Tile* tile = solids->get_tile(x, y); if(!tile) continue; - // skip non-solid tiles - if(!(tile->getAttributes() & Tile::SOLID)) + // skip non-solid tiles, except water + if (tile->getAttributes() & Tile::WATER) + water = true; + if(!water && !(tile->getAttributes() & Tile::SOLID)) continue; if(tile->getAttributes() & Tile::SLOPE) { // slope tile @@ -123,14 +128,24 @@ 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 (water) + return 0; //collision with water tile - don't draw splash + else { + if ((hit.normal.x == 1) && (hit.normal.y == 0)) + return 2; //collision from right + else return 1; //collision from above + } + } } RainParticleSystem::RainParticleSystem() { - rainimages[0] = new Surface(datadir+"/images/objects/particles/rain0.png", true); - rainimages[1] = new Surface(datadir+"/images/objects/particles/rain1.png", true); + rainimages[0] = new Surface("images/objects/particles/rain0.png"); + rainimages[1] = new Surface("images/objects/particles/rain1.png"); virtual_width = SCREEN_WIDTH * 2; @@ -138,12 +153,12 @@ RainParticleSystem::RainParticleSystem() size_t raindropcount = size_t(virtual_width/6.0); for(size_t i=0; ipos.x = rand() % int(virtual_width); - particle->pos.y = rand() % int(virtual_height); - int rainsize = rand() % 2; + particle->pos.x = systemRandom.rand(int(virtual_width)); + particle->pos.y = systemRandom.rand(int(virtual_height)); + int rainsize = systemRandom.rand(2); particle->texture = rainimages[rainsize]; do { - particle->speed = (rainsize+1)*45 + (float(rand()%10)*.4); + particle->speed = (rainsize+1)*45 + systemRandom.randf(3.6); } while(particle->speed < 1); particle->speed *= 10; // gravity @@ -154,14 +169,14 @@ RainParticleSystem::RainParticleSystem() void RainParticleSystem::parse(const lisp::Lisp& reader) { - reader.get("layer", layer); + reader.get("z-pos", z_pos); } void RainParticleSystem::write(lisp::Writer& writer) { writer.start_list("particles-rain"); - writer.write_int("layer", layer); + writer.write_int("z-pos", z_pos); writer.end_list("particles-rain"); } @@ -182,23 +197,25 @@ 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; + if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)){ + bool vertical = (col == 2); 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_x = systemRandom.rand(int(virtual_width)) + int(abs_x); int new_y = 0; //FIXME: Don't move particles over solid tiles particle->pos.x = new_x; @@ -209,8 +226,8 @@ void RainParticleSystem::update(float elapsed_time) CometParticleSystem::CometParticleSystem() { - cometimages[0] = new Surface(datadir+"/images/creatures/mr_bomb/exploding-left-0.png", true); - cometimages[1] = new Surface(datadir+"/images/creatures/mr_bomb/exploding-left-0.png", true); + cometimages[0] = new Surface("images/creatures/mr_bomb/exploding-left-0.png"); + cometimages[1] = new Surface("images/creatures/mr_bomb/exploding-left-0.png"); virtual_width = SCREEN_WIDTH * 2; @@ -218,12 +235,12 @@ CometParticleSystem::CometParticleSystem() size_t cometcount = 2; for(size_t i=0; ipos.x = rand() % int(virtual_width); - particle->pos.y = rand() % int(virtual_height); - int cometsize = rand() % 2; + particle->pos.x = systemRandom.rand(int(virtual_width)); + particle->pos.y = systemRandom.rand(int(virtual_height)); + int cometsize = systemRandom.rand(2); particle->texture = cometimages[cometsize]; do { - particle->speed = (cometsize+1)*30 + (float(rand()%10)*.4); + particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6); } while(particle->speed < 1); particle->speed *= 10; // gravity @@ -234,14 +251,14 @@ CometParticleSystem::CometParticleSystem() void CometParticleSystem::parse(const lisp::Lisp& reader) { - reader.get("layer", layer); + reader.get("z-pos", z_pos); } void CometParticleSystem::write(lisp::Writer& writer) { writer.start_list("particles-comets"); - writer.write_int("layer", layer); + writer.write_int("z-pos", z_pos); writer.end_list("particles-comets"); } @@ -262,11 +279,12 @@ 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) { + int col = collision(particle, Vector(-movement, movement)); + if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { + if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) { Sector::current()->add_object(new Bomb(particle->pos, LEFT)); } - int new_x = (rand() % int(virtual_width)) + int(abs_x); + int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x); int new_y = 0; //FIXME: Don't move particles over solid tiles particle->pos.x = new_x;