Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

8.8. Letting the player win

Right now, the game is pretty pointless because you simply can't win; to fix that, you need to implement a scoring system of some description. In the case of this game, the scoring system is based on the amount of attempts (clicks) it takes the player to knock all of the asteroids out of the platform. This requires you to know how many asteroids have been knocked out of the platform, and how many clicks have been made (the score). After every click you then update the UI to show the player the current score. Once all of the asteroids have been knocked out, you end the game and show the player their final score — they win.

8.8.1. Updating the score

The first step is to set up the variable that will hold the score, so add the following declaration underneath the powerY variable at the top of the JavaScript:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial