1. Particles

So, my breakout game is half finish. I have collision detection, load and destroy functions, as well as render functions.

for some cool effect, the particle system will have to get involved. I have particles for the ball when it collides to the walls and the bar. The final thing is the particles for the bricks. There will be 5 or 6 pieces of quad (or triangles) fly out randomly when the ball hit the bricks. But, there are certain problems i'm just unsure about.

- I start the game by loading the position, textures from a file and create the bricks for the level, and this is my brick class:
Code:
```class Brick
{
public:
vect2 Pos;
vect2* Vertices;

Brick()
{}

~Brick(){}

vect2 *BuildBlock(int width, int height)
{
Vertices = new vect2[4];
Vertices[0] = vect2(0, 0);
Vertices[1] = vect2(width, 0);
Vertices[2] = vect2(width, height);
Vertices[3] = vect2(0, height);
return Vertices;
}
void Render()
{

glPushMatrix();
glTranslated(Pos.x, Pos.y, 0.0f);
glColor3f(1, 1, 1);
for(int j=0; j<4; j++)
{
glVertex2d(Vertices[j].x, Vertices[j].y);
}
glEnd();
}

void Destroy()
{
Vertices = NULL;
}
};```
Then i create an array of vector and push all the brick objects and empty the load function.

So when the ball hit one of the brick, the vector will erase the block out the array:
Code:
```for(int j=0; j<block.size(); j++)
{
if(ball is collide with the bricks)
{
block[j].destroy();
block.erase(block.begin()+j);
}
}```
Now, there is the hard part, should i include the particle function in the brick class and then delay the destroy function? Because once the block is erase out the vector array, the particle function will not run. The other way is create an outside particle function and set the particles' position equal the brick's position that had been hit. Then i realize, the particles' position must be going somewhere before it can be reuse at another time when another brick is hit. (make sense?)

Can anyone point out a better way for this problem? Thanks

2. I'd separate it into a class of its own. When the brick is destroyed (call the destroy method?) call a CreateParticle function/method with the position of the brick as an argument which creates the particle(s).

3. what if 2 blocks are hit at the same time? Should the function being call twice?

4. If you want twice the amount of particles if two are destroyed then yes! It's up to you.

5. The problem you will run into is that a particle system must track every particle that is currently active. What if you hit 5 blocks or hit a block before the old particle effect from the previous hit block expires?

So you can either set a max value for particles or you can use a list and add/remove particles as needed.

Personally since a particle effect is relatively quick I would fire off a thread for each effect and the thread would be responsible for updating the particle positions. When all of the particles are dead, the thread would terminate and return.

6. How about create the particles classes and push them into array of vector, then attach to each brick. So when the particles are done, delete them from the array

7. Another method which lends itself to hardware quite nicely is batching of particles. Process a batch of particles and then process another batch. Send the batches to the hardware for rendering. If done correctly this can eliminate a lot of pipeline stalls.

8. Originally Posted by Bubba
Another method which lends itself to hardware quite nicely is batching of particles. Process a batch of particles and then process another batch. Send the batches to the hardware for rendering. If done correctly this can eliminate a lot of pipeline stalls.