tags:

views:

32

answers:

1

I'm making a Asteroids game but I can not get to play more than one explosion at a time. Just get to do one at a time ...

This is my code I call in the main loop:

for(i = 0; i < MAX_SHOTS; i++) {
    for(j = 0; j < MAX_ASTEROIDS; j++) {
        if(shot[i].CheckCollision(asteroide[j])) {
            shot[i].SetPos(-100, 0);
            explosionSnd.Play();

            numAst = j;
            explosion[numExp++].Enable(true);

            if(numExp == MAX_EXPLOSIONS-1) {
                numExp = 1;
            }
        }
    }
}

for(i = 1; i < MAX_EXPLOSIONS; i++) {
    if(explosion[i].Enable()) {
        explosion[i].SetPos(asteroide[numAst].GetX(), asteroide[numAst].GetY());
        explosion[i].Draw();
        if(explosion[i].GetFrame() == 5) {
            explosion[i].Enable(false);
        }
    }
}

If I shot to an asteroid and after I shot to another, the animation is cut and goes to the new asteroid.

Any help?

Thank you.

+4  A: 

Hi,

Inside your second loop, you're moving each explosion to the location of the asteroid asteroide[numAst] - you're playing all the explosions, just all at the same place!

You should only position the explosion once after you Enable(true) it, when it's created in the first loop, not each time you draw it.

Hope that helps.

deanWombourne
Thanks, I've managed with what you said xDIn the end I removed the explosion follow the asteroid and the effect is much better
Puyover