Chapter 7, Exercise 2 – Tapering Level Difficulty

As noted in “Multiple Levels and High Scores” on page 138, the game will become unplayable after a few levels because the number of bubbles allowed becomes too small. Instead of subtracting five bubbles per level, create an algorithm that makes levels progressively harder but makes it possible to complete a level. Perhaps the smallest number of fired bubbles a player can complete a level in is 30, and we want them to reach this level of difficulty on level 15. Before this point, the step from level 1 to 2 might be, say, five bubbles fewer, but the step from level 14 to 15 might be only one fewer. Write an equation or other method to decrease the number of bubbles allowed and increase the difficulty in this way.

We could decide that, say, 40 bubbles is the minimum we’ll give the user to complete a level. An algorithm such as the following would give the player fewer bubbles in a tapered way, so that the jump from level 1 to level 2 is bigger than level 2 to level 3. In graph terms, we want a bubble count that looks something like the following:

Tapering Bubble Shooter Level Difficulty

One function to do this involves using an inverse of the exponential graph. Setting the function to calculate the number of bubbles to assign in a level to the following (in startGame in game.js) does the trick:

numBubbles = 40 + Math.round(Math.pow(Math.exp(-level),1/4) * 30);

This gives 70 bubbles on level 1, 63 on level 2, 58 on level 3, and then goes down to 41 bubbles by level 15 and finally 40 bubbles on level 18. The number of bubbles never drops below 40.
Take a look at various mathematical graphs and try to find other ways of achieving a similar result.

Leave a Reply

Your email address will not be published. Required fields are marked *