Updating the score label to display the level

In our game, we have a label that displays the score or the words "Game Over". Now that we have implemented levels as well, we also want to display the level within that label.

As shown in the following screenshot, we used the join block to join two pieces of information and display it in the label—the word Score: (there is a blank space after the colon) and the value of the score. Now that we want to display the level, we will add three more pieces of information to this join block. There is another blank space after the score (value), followed by the word "Level: " (there is also a blank space after the colon here), and finally the value of level.

To make room for these three new pieces of information, we need to add strings to the existing join block. Click on the blue square in the top left corner of the join block. This will open a pop-up window. Inside this popup, drag the string block from the top left corner into the join block on the right-hand side. Do this three times. Each time you add another string, you will see a new space appear in the join block below the get global score block.

Updating the score label to display the level

If you have done this correctly, there will be three empty slots, as shown in the following screenshot. Now, click anywhere outside the popup to close the pop-up menu.

Updating the score label to display the level

Now, we are ready to plug in the three new pieces of information related to the levels. Plug in a blank text box in the first open slot (the blank text block is the first block in Text block's drawer). Even though it seems like this contains a blank space, we must make one. Click inside the blank text and press your keyboard's spacebar to create a space. In the next empty slot, plug in another blank text block, and click and type in the word Level: with a space after the colon.

As you might have correctly guessed, the last piece of text we will plug into the join block is the level value. You might be wondering where this level value is going to come from. We will actually calculate this from the current score value.

When we implemented the levels, we assumed that an increase in score by 5 will trigger a level change. Hence, scores 0 to 4 correspond to level 0, scores 5 to 9 correspond to level 1, scores 10 to 14 correspond to level 2, and so on. We can use some math to calculate the level from the score. As you might have guessed, the math that we are going to use here is the quotient operation. More specifically, we will divide the score by 5 and use the quotient part to determine our levels.

To use the quotient block, go back to Math Blocks drawer and drag a modulo block. Then, click on the downward pointing triangle to change it to quotient. Copy a get global score block and plug it into the first open socket of the quotient block. Insert a Math number block into the second opening and change it to 5. The completed blocks are shown in the following screenshot:

Updating the score label to display the level

This is an ideal time to reconnect your mobile device to your Fling app. Your Label will now display both the score and the level, as shown in the following screenshot:

Updating the score label to display the level
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset