#include <particlesystem_interactive.hpp>
Inherits GameObject.
Inherited by CometParticleSystem, and RainParticleSystem.
Public Member Functions | |
ParticleSystem_Interactive () | |
virtual | ~ParticleSystem_Interactive () |
virtual void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
Protected Member Functions | |
int | collision (Particle *particle, Vector movement) |
Protected Attributes | |
int | z_pos |
std::vector< Particle * > | particles |
float | virtual_width |
float | virtual_height |
Classes | |
class | Particle |
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. This version of the particle system class doesn't use virtual screen coordinates, but Interactive ones. Particle systems which need Interactive 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.
Definition at line 38 of file particlesystem_interactive.hpp.
ParticleSystem_Interactive::ParticleSystem_Interactive | ( | ) |
Definition at line 27 of file particlesystem_interactive.cpp.
References SCREEN_HEIGHT, SCREEN_WIDTH, virtual_height, virtual_width, and z_pos.
00027 : 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 }
ParticleSystem_Interactive::~ParticleSystem_Interactive | ( | ) | [virtual] |
Definition at line 38 of file particlesystem_interactive.cpp.
References particles.
00039 { 00040 std::vector<Particle*>::iterator i; 00041 for(i = particles.begin(); i != particles.end(); ++i) { 00042 delete *i; 00043 } 00044 }
void ParticleSystem_Interactive::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Implements GameObject.
Definition at line 46 of file particlesystem_interactive.cpp.
References DrawingContext::draw_surface(), particles, DrawingContext::pop_transform(), DrawingContext::push_transform(), and z_pos.
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 }
Definition at line 60 of file particlesystem_interactive.cpp.
References Sector::current(), collision::intersects(), CollisionHit::left, Rectf::move(), ParticleSystem_Interactive::Particle::pos, collision::rectangle_aatriangle(), CollisionHit::right, collision::set_rectangle_rectangle_constraints(), Tile::SOLID, Sector::solid_tilemaps, Tile::WATER, Vector::x, and Vector::y.
Referenced by RainParticleSystem::update(), and CometParticleSystem::update().
00061 { 00062 using namespace collision; 00063 00064 // calculate rectangle where the object will move 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 // test with all tiles in this rectangle 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 // FIXME Handle a nonzero tilemap offset 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 // skip non-solid tiles, except water 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 ()) { // slope tile 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 { // normal rectangular tile 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 // TODO don't use magic numbers here... 00115 00116 // did we collide at all? 00117 if(!constraints.has_constraints()) 00118 return -1; 00119 00120 const CollisionHit& hit = constraints.hit; 00121 if (water) { 00122 return 0; //collision with water tile - don't draw splash 00123 } else { 00124 if (hit.right || hit.left) { 00125 return 2; //collision from right 00126 } else { 00127 return 1; //collision from above 00128 } 00129 } 00130 00131 return 0; 00132 }
int ParticleSystem_Interactive::z_pos [protected] |
Definition at line 68 of file particlesystem_interactive.hpp.
Referenced by draw(), RainParticleSystem::parse(), CometParticleSystem::parse(), and ParticleSystem_Interactive().
std::vector<Particle*> ParticleSystem_Interactive::particles [protected] |
Definition at line 69 of file particlesystem_interactive.hpp.
Referenced by CometParticleSystem::CometParticleSystem(), draw(), RainParticleSystem::RainParticleSystem(), RainParticleSystem::update(), CometParticleSystem::update(), and ~ParticleSystem_Interactive().
float ParticleSystem_Interactive::virtual_width [protected] |
Definition at line 70 of file particlesystem_interactive.hpp.
Referenced by CometParticleSystem::CometParticleSystem(), ParticleSystem_Interactive(), RainParticleSystem::RainParticleSystem(), RainParticleSystem::update(), and CometParticleSystem::update().
float ParticleSystem_Interactive::virtual_height [protected] |
Definition at line 71 of file particlesystem_interactive.hpp.
Referenced by CometParticleSystem::CometParticleSystem(), ParticleSystem_Interactive(), and RainParticleSystem::RainParticleSystem().