user1816133
user1816133

Reputation:

Action Script 3. Stop game after loop 3 times

I'm creating flash game, Idea is falling objects (in this case apples) from the sky and player need to click on apples. I need to make that when 3 apples are missed show "Game over" or etc, I need to stop game. I know this is simple for you professionals :)
Thank you for answers.

This is part of code:

 for (var i = apples.length-1; i >= 0; i--)
        {
            apples[i].y += gravity;
                                                  //here I need to add loop?
            if (apples[i].y > C.APPLE_END_Y)
            {
                mcGameStage.removeChild(apples[i]); 

                apples.splice(i,1);
            }
        } 

Upvotes: 0

Views: 181

Answers (1)

Panzercrisis
Panzercrisis

Reputation: 4750

I remember you having the function called update() in your last post about this program. Whatever class all of this is happening in, place this variable:

private var m_iLives:int = 3;

Then, in your update() function, use this code:

for (var i = apples.length-1; i >= 0; i--)
{
    apples[i].y += gravity;
    if (apples[i].y > C.APPLE_END_Y)
    {
        mcGameStage.removeChild(apples[i]); 
        apples.splice(i,1);
        m_iLives--;

        if (!m_iLives)
        {
            gameOverFunc();
            break;
        }
    }
}

Upvotes: 1

Related Questions