How to deduct chances in a game I created on Xcode for iPad

37 views Asked by At

The subject of this game is the player must avoid the cans falling from the top. I want to give the player 3 chances, this is my code:

_chancesCount = 0;
    if (CGRectIntersectsRect(_cola.frame, _cabbie.frame)) {
        _chancesCount += 1;
    }
    if (CGRectIntersectsRect(_coffee.frame, _cabbie.frame)) {
        _chancesCount += 1;
    }
    if (CGRectIntersectsRect(_tea.frame, _cabbie.frame)) {
        _chancesCount += 1;
    }
    if (CGRectIntersectsRect(_soda.frame, _cabbie.frame)) {
    _chancesCount += 1;
    }
    if (CGRectIntersectsRect(_beer.frame, _cabbie.frame)) {
        _chancesCount += 1;
    }
    if (_chancesCount == 3) {
        _currentState = _STATE_GAMEOVER;
    }

I setup a label to display how many chance the player have left but it seems that whenever the can hit and leaves _cabbie.frame(a yellow creature). chanceCounts automatically turns back into 0. so there must be 3 cans hitting cabbie at the same time to make the game over.

0

There are 0 answers