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();
glLoadIdentity();
glTranslated(Pos.x, Pos.y, 0.0f);
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
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