#include <particlesystem.hpp>
Inherits GameObject.
Inherited by CloudParticleSystem, GhostParticleSystem, and SnowParticleSystem.
Public Member Functions | |
ParticleSystem (float max_particle_size=60) | |
virtual | ~ParticleSystem () |
virtual void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
Protected Attributes | |
float | max_particle_size |
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. The coordinate system used here is a virtual one. It would be a bad idea to populate whole levels with particles. So we're using a virtual rectangle here that is tiled onto the level when drawing. This rect.has the size (virtual_width, virtual_height). We're using modulo on the particle coordinates, so when a particle leaves left, it'll reenter at the right side.
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 44 of file particlesystem.hpp.
ParticleSystem::ParticleSystem | ( | float | max_particle_size = 60 |
) |
Definition at line 25 of file particlesystem.cpp.
References LAYER_BACKGROUND1, SCREEN_HEIGHT, SCREEN_WIDTH, virtual_height, virtual_width, and z_pos.
00025 : 00026 max_particle_size(max_particle_size), 00027 z_pos(), 00028 particles(), 00029 virtual_width(), 00030 virtual_height() 00031 { 00032 virtual_width = SCREEN_WIDTH + max_particle_size * 2; 00033 virtual_height = SCREEN_HEIGHT + max_particle_size *2; 00034 z_pos = LAYER_BACKGROUND1; 00035 }
ParticleSystem::~ParticleSystem | ( | ) | [virtual] |
Definition at line 37 of file particlesystem.cpp.
References particles.
00038 { 00039 std::vector<Particle*>::iterator i; 00040 for(i = particles.begin(); i != particles.end(); ++i) { 00041 delete *i; 00042 } 00043 }
void ParticleSystem::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Implements GameObject.
Definition at line 45 of file particlesystem.cpp.
References DrawingContext::draw_surface(), DrawingContext::get_translation(), max_particle_size, particles, DrawingContext::pop_transform(), DrawingContext::push_transform(), DrawingContext::set_translation(), virtual_height, virtual_width, Vector::x, Vector::y, and z_pos.
00046 { 00047 float scrollx = context.get_translation().x; 00048 float scrolly = context.get_translation().y; 00049 00050 context.push_transform(); 00051 context.set_translation(Vector(max_particle_size,max_particle_size)); 00052 00053 std::vector<Particle*>::iterator i; 00054 for(i = particles.begin(); i != particles.end(); ++i) { 00055 Particle* particle = *i; 00056 00057 // remap x,y coordinates onto screencoordinates 00058 Vector pos; 00059 00060 pos.x = fmodf(particle->pos.x - scrollx, virtual_width); 00061 if(pos.x < 0) pos.x += virtual_width; 00062 00063 pos.y = fmodf(particle->pos.y - scrolly, virtual_height); 00064 if(pos.y < 0) pos.y += virtual_height; 00065 00066 //if(pos.x > virtual_width) pos.x -= virtual_width; 00067 //if(pos.y > virtual_height) pos.y -= virtual_height; 00068 00069 context.draw_surface(particle->texture, pos, particle->angle, Color(1.0f, 1.0f, 1.0f), Blend(), z_pos); 00070 } 00071 00072 context.pop_transform(); 00073 }
float ParticleSystem::max_particle_size [protected] |
int ParticleSystem::z_pos [protected] |
Definition at line 76 of file particlesystem.hpp.
Referenced by draw(), SnowParticleSystem::parse(), GhostParticleSystem::parse(), CloudParticleSystem::parse(), and ParticleSystem().
std::vector<Particle*> ParticleSystem::particles [protected] |
Definition at line 77 of file particlesystem.hpp.
Referenced by CloudParticleSystem::CloudParticleSystem(), draw(), GhostParticleSystem::GhostParticleSystem(), SnowParticleSystem::SnowParticleSystem(), SnowParticleSystem::update(), GhostParticleSystem::update(), CloudParticleSystem::update(), and ~ParticleSystem().
float ParticleSystem::virtual_width [protected] |
Definition at line 78 of file particlesystem.hpp.
Referenced by CloudParticleSystem::CloudParticleSystem(), draw(), GhostParticleSystem::GhostParticleSystem(), ParticleSystem(), SnowParticleSystem::SnowParticleSystem(), and GhostParticleSystem::update().
float ParticleSystem::virtual_height [protected] |
Definition at line 79 of file particlesystem.hpp.
Referenced by CloudParticleSystem::CloudParticleSystem(), draw(), ParticleSystem(), and GhostParticleSystem::update().