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:
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. };
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); // increase the success count audiogame.successCount+=1; // keep only 5 success count max. audiogame.successCount = Math.min(5, audiogame.successCount); // increase the total success...