00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "object/particlesystem_interactive.hpp"
00018
00019 #include "math/aatriangle.hpp"
00020 #include "object/tilemap.hpp"
00021 #include "supertux/collision.hpp"
00022 #include "supertux/tile.hpp"
00023
00024
00025
00026
00027 ParticleSystem_Interactive::ParticleSystem_Interactive() :
00028 z_pos(),
00029 particles(),
00030 virtual_width(),
00031 virtual_height()
00032 {
00033 virtual_width = SCREEN_WIDTH;
00034 virtual_height = SCREEN_HEIGHT;
00035 z_pos = 0;
00036 }
00037
00038 ParticleSystem_Interactive::~ParticleSystem_Interactive()
00039 {
00040 std::vector<Particle*>::iterator i;
00041 for(i = particles.begin(); i != particles.end(); ++i) {
00042 delete *i;
00043 }
00044 }
00045
00046 void ParticleSystem_Interactive::draw(DrawingContext& context)
00047 {
00048 context.push_transform();
00049
00050 std::vector<Particle*>::iterator i;
00051 for(i = particles.begin(); i != particles.end(); ++i) {
00052 Particle* particle = *i;
00053 context.draw_surface(particle->texture, particle->pos, z_pos);
00054 }
00055
00056 context.pop_transform();
00057 }
00058
00059 int
00060 ParticleSystem_Interactive::collision(Particle* object, Vector movement)
00061 {
00062 using namespace collision;
00063
00064
00065 float x1, x2;
00066 float y1, y2;
00067 x1 = object->pos.x;
00068 x2 = x1 + 32 + movement.x;
00069 y1 = object->pos.y;
00070 y2 = y1 + 32 + movement.y;
00071 bool water = false;
00072
00073
00074 int starttilex = int(x1-1) / 32;
00075 int starttiley = int(y1-1) / 32;
00076 int max_x = int(x2+1);
00077 int max_y = int(y2+1);
00078
00079 Rectf dest(x1, y1, x2, y2);
00080 dest.move(movement);
00081 Constraints constraints;
00082
00083 for(std::list<TileMap*>::const_iterator i = Sector::current()->solid_tilemaps.begin(); i != Sector::current()->solid_tilemaps.end(); i++) {
00084 TileMap* solids = *i;
00085
00086 for(int x = starttilex; x*32 < max_x; ++x) {
00087 for(int y = starttiley; y*32 < max_y; ++y) {
00088 const Tile* tile = solids->get_tile(x, y);
00089 if(!tile)
00090 continue;
00091
00092 if(! (tile->getAttributes() & (Tile::WATER | Tile::SOLID)))
00093 continue;
00094
00095 Rectf rect = solids->get_tile_bbox(x, y);
00096 if(tile->is_slope ()) {
00097 AATriangle triangle = AATriangle(rect, tile->getData());
00098
00099 if(rectangle_aatriangle(&constraints, dest, triangle)) {
00100 if(tile->getAttributes() & Tile::WATER)
00101 water = true;
00102 }
00103 } else {
00104 if(intersects(dest, rect)) {
00105 if(tile->getAttributes() & Tile::WATER)
00106 water = true;
00107 set_rectangle_rectangle_constraints(&constraints, dest, rect);
00108 }
00109 }
00110 }
00111 }
00112 }
00113
00114
00115
00116
00117 if(!constraints.has_constraints())
00118 return -1;
00119
00120 const CollisionHit& hit = constraints.hit;
00121 if (water) {
00122 return 0;
00123 } else {
00124 if (hit.right || hit.left) {
00125 return 2;
00126 } else {
00127 return 1;
00128 }
00129 }
00130
00131 return 0;
00132 }
00133
00134