Start typing to search...

Manage game difficulty

In the previous section of the customizable game tutorial, you made the game playable by adding ways to score and to lose. But, it still might be a little too repetitive and easy.

In this section, you’ll make the game progressively more difficult over time, so that users have more incentive to compete on the leaderboard.

By the end of this section, you should feel comfortable:

  • Defining values that control the difficulty of the game.

  • Increasing the difficulty values at a set interval.

Defining starting values

Remember the function for handling the spawn logic? You’ll use something similar to handle the difficulty.

Start by defining the game settings that control the difficulty. In frontend/src/Components/Game/preload.js, add the following properties.

const initializeValues = () => {
    game.difficultyIncreasePeriod = 2;
    game.difficultyIncreaseTimer = 2;
    game.difficultyIncreaseAmount = 0.1;
    game.speedLimit = 12;
    game.speedIncrease = 0.1;

Increasing difficulty during game play

Next, define a function to increase the difficulty as the game progresses. In frontend/src/Components/Game/draw.js, add the following code.

const draw = () => {

const manageDifficulty = () => {
    game.difficultyIncreaseTimer -=;

    if (game.difficultyIncreaseTimer <= 0) {
        game.difficultyIncreaseTimer = game.difficultyIncreasePeriod;

const increaseDifficulty = () => {
    if (game.spawnPeriodMin > game.spawnPeriodLimit) {
        game.spawnPeriodMin -= game.difficultyIncreaseAmount;
        game.spawnPeriodMax -= game.difficultyIncreaseAmount;

    if (game.speedMax < game.speedLimit) {
        game.speedMax += game.speedIncrease;
        game.speedMin += game.speedIncrease;

Using a timer, you periodically increase the difficulty by changing some game values – up to a point. It’s important to set a limit to prevent the game from becoming totally unplayable, which most users wouldn’t consider a fun experience.

Every time the difficulty increases, this function will:

  • Slightly decrease the period between the spawning of collectibles.

  • Slightly increase the falling speed of collectibles.

Wrapping up

Congratulations! You’ve finished developing the main part of your game. Of course, you can go back and modify things or add new features. Everything’s a bonus from now on!

In the next section, you’ll learn how to make the game assets customizable.