X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fparticlesystem_interactive.cpp;h=9923c03c7b2bf708a62d1633114c576404f997ce;hb=bb423166352cd63fdf40b0f51b6699a47890faee;hp=40a71478239ea5b27f4df0b24190830ee3489ac0;hpb=73259e6cd83bae601cb8ce49b6e7a0df1d4de087;p=supertux.git
diff --git a/src/object/particlesystem_interactive.cpp b/src/object/particlesystem_interactive.cpp
index 40a714782..9923c03c7 100644
--- a/src/object/particlesystem_interactive.cpp
+++ b/src/object/particlesystem_interactive.cpp
@@ -15,12 +15,8 @@
// along with this program. If not, see .
#include "object/particlesystem_interactive.hpp"
-#include "supertux/main.hpp"
#include "math/aatriangle.hpp"
-#include "math/random_generator.hpp"
-#include "object/camera.hpp"
-#include "object/rainsplash.hpp"
#include "object/tilemap.hpp"
#include "supertux/collision.hpp"
#include "supertux/tile.hpp"
@@ -28,7 +24,11 @@
//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()
+ParticleSystem_Interactive::ParticleSystem_Interactive() :
+ z_pos(),
+ particles(),
+ virtual_width(),
+ virtual_height()
{
virtual_width = SCREEN_WIDTH;
virtual_height = SCREEN_HEIGHT;
@@ -76,12 +76,13 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement)
int max_x = int(x2+1);
int max_y = int(y2+1);
- Rect dest = Rect(x1, y1, x2, y2);
+ Rectf dest(x1, y1, x2, y2);
dest.move(movement);
Constraints constraints;
for(std::list::const_iterator i = Sector::current()->solid_tilemaps.begin(); i != Sector::current()->solid_tilemaps.end(); i++) {
TileMap* solids = *i;
+ // FIXME Handle a nonzero tilemap offset
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);
@@ -91,18 +92,15 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement)
if(! (tile->getAttributes() & (Tile::WATER | Tile::SOLID)))
continue;
+ Rectf rect = solids->get_tile_bbox(x, y);
if(tile->getAttributes() & Tile::SLOPE) { // slope tile
- AATriangle triangle;
- Vector p1(x*32, y*32);
- Vector p2((x+1)*32, (y+1)*32);
- triangle = AATriangle(p1, p2, tile->getData());
+ AATriangle triangle = AATriangle(rect, tile->getData());
if(rectangle_aatriangle(&constraints, dest, triangle)) {
if(tile->getAttributes() & Tile::WATER)
water = true;
}
} else { // normal rectangular tile
- Rect rect(x*32, y*32, (x+1)*32, (y+1)*32);
if(intersects(dest, rect)) {
if(tile->getAttributes() & Tile::WATER)
water = true;
@@ -133,142 +131,4 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement)
return 0;
}
-RainParticleSystem::RainParticleSystem()
-{
- rainimages[0] = new Surface("images/objects/particles/rain0.png");
- rainimages[1] = new Surface("images/objects/particles/rain1.png");
-
- virtual_width = SCREEN_WIDTH * 2;
-
- // create some random raindrops
- size_t raindropcount = size_t(virtual_width/6.0);
- for(size_t i=0; ipos.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 + systemRandom.randf(3.6);
- } while(particle->speed < 1);
- particle->speed *= 10; // gravity
-
- particles.push_back(particle);
- }
-}
-
-void
-RainParticleSystem::parse(const Reader& reader)
-{
- reader.get("z-pos", z_pos);
-}
-
-RainParticleSystem::~RainParticleSystem()
-{
- for(int i=0;i<2;++i)
- delete rainimages[i];
-}
-
-void RainParticleSystem::update(float elapsed_time)
-{
- std::vector::iterator i;
- for(
- i = particles.begin(); i != particles.end(); ++i) {
- RainParticle* particle = (RainParticle*) *i;
- float movement = particle->speed * elapsed_time;
- float abs_x = Sector::current()->camera->get_translation().x;
- float abs_y = Sector::current()->camera->get_translation().y;
- particle->pos.y += movement;
- particle->pos.x -= 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) && (col >= 1)){
- bool vertical = (col == 2);
- int splash_x, splash_y;
- 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));
- }
- // 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 = 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;
- particle->pos.y = new_y;
- }
- }
-}
-
-CometParticleSystem::CometParticleSystem()
-{
- 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;
-
- // create some random comets
- size_t cometcount = 2;
- for(size_t i=0; ipos.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 + systemRandom.randf(3.6);
- } while(particle->speed < 1);
- particle->speed *= 10; // gravity
-
- particles.push_back(particle);
- }
-}
-
-void
-CometParticleSystem::parse(const Reader& reader)
-{
- reader.get("z-pos", z_pos);
-}
-
-CometParticleSystem::~CometParticleSystem()
-{
- for(int i=0;i<2;++i)
- delete cometimages[i];
-}
-
-void CometParticleSystem::update(float elapsed_time)
-{
- (void) elapsed_time;
-#if 0
- std::vector::iterator i;
- for(
- i = particles.begin(); i != particles.end(); ++i) {
- CometParticle* particle = (CometParticle*) *i;
- float movement = particle->speed * elapsed_time;
- float abs_x = Sector::current()->camera->get_translation().x;
- float abs_y = Sector::current()->camera->get_translation().y;
- particle->pos.y += movement;
- particle->pos.x -= movement;
- 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 = 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;
- particle->pos.y = new_y;
- }
- }
-#endif
-}
-
/* EOF */