Time for action – removing missed melody notes

We will store some game play statistics and use them to adjust the melody volume. We will continue with our JavaScript file:

  1. First, add the following variables in the variable declaration region:
    var audiogame = {
      totalSuccessCount: 0,
    
      // storing the success count of last 5 results.
      successCount: 5,
    
      // existing code goes here.
    
    };
  2. We want to not only remove a dot but also keep track of the result when we hit it by using a keyboard. Add the following code inside the hitOnLine function:
    // check if hit a music note dot for(var i in audiogame.dots) { if (lineNo === audiogame.dots[i].line && Math.abs(audiogame.dots[i].distance) < 20) { // remove the hit dot from the dots array audiogame.dots.splice(i, 1); ...

Get HTML5 Game Development by Example : Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.