Time for action – detecting when we clear the level
How do we know when the level is over? The answer is simple, that is, when all the bricks are broken; so, let's build the simple answer. We know that at the start of the game, there are 40 bricks on the screen. Let's follow the given steps to detect when we clear the level:
- The cloud id variable has a record of the total number of bricks we built. Let's assign that value to a new variable named level hits. Then, we'll actually count down the level hits variable with each broken brick.
- Select the brick sprite. Add the set () to () block to the end of the stack that uses the lay brick custom block. Select level hits as the variable and drag the cloud id reporter block from the Data palette to the to value. Check your blocks against the following screenshot:
- Each time the ball breaks a brick, we will reduce the value in the level hits variable. Add a change (level hits) by (-1) block after the change (score) by (1...