Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
App Inventor 2 Essentials

You're reading from  App Inventor 2 Essentials

Product type Book
Published in Apr 2016
Publisher
ISBN-13 9781785281105
Pages 248 pages
Edition 1st Edition
Languages

Adding a scoring feature


Since most game apps include some sort of scoring feature, we will add this code to our Fling app. The score will display in the same label that will also display the Game Over text.

Coding scoring blocks

We left off in the last chapter with the ball bouncing off all the edges except the bottom edge. Now, we want to program the app to increase the score by one point every time the ball reaches the top edge. We will use another if/then block and add it into the else portion of the existing if/then/else block within the when Ball1.EdgeReached event, as shown in the following screenshot:

Can you guess what block will fit in the if opening? If the ball hits the top edge, then the app will increase the score by 1. In Chapter 3, Navigating the App Inventor Platform, you learned that the bottom edge is represented by -1 (and the top edge is represented by 1). Since we've already created an if/then scenario for the ball hitting the bottom edge, we can copy this set of blocks...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}