Home · Academy · Robotics & Coding · Programming with Scratch · Score and Levels in Game Design

Score and Levels in Game Design

Learn to add score, lives and level transitions that make a game harder step by step.

LESSON COMPASS

What will you use this page for?

Core idea

What makes a game engaging is collecting points, losing lives and moving to new levels as it gets harder. In this lesson I learn to track score and lives with variables in Scratch, jump to a new level when the score reaches a certain number, and end the game.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Forgetting to reset the variable If you don't set score and lives at the start, your second play begins with the previous score. Always set the variables to their starting values when the green flag is clicked. The "equals" trap in a fast loop The block if <score = 10> is only true when the score is exactly 10. If the…

Next connection

Debugging and Testing: When our game doesn't work the way we expected, we learn to find and fix the mistake step by step.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration30–45 min
PrerequisiteSimple Physics
ContentStandard lesson · 1,689 words
Last updated

One-sentence summary

What makes a game engaging is collecting points, losing lives and moving to new levels as it gets harder. In this lesson I learn to track score and lives with variables in Scratch, jump to a new level when the score reaches a certain number, and end the game.

Why it matters

We already learned how to move a character and handle collisions. But so far our game had no real "goal." The thing that answers the question "why should I keep playing?" is usually the score: collect stars, escape the enemy, beat the high score.

Score and lives add a goal and a risk to a game. Levels keep the game from feeling repetitive. A game that is easy in the first level speeds up a little in the second. That way the player neither gets bored nor gives up right away.

These ideas are not only for games. The points you earn in a language app, the scoreboard in a sports match and a course that advances level by level all use the same logic: measure progress, give feedback, and increase difficulty step by step.

Score and lives with variables

What is a variable?

A variable is like a box where we can store a value. The number inside it can change during the game. In Scratch, variables are created in the Variables category.

A game usually needs two variables:

After creating a variable, remember to reset it at the start of the game. Otherwise you start with the score left over from the previous round.

when green flag clicked
set score to 0
set lives to 3

Here score starts at zero and lives starts with 3 chances. These two blocks come from the Events and Variables categories.

Increasing the score

When the player touches a star, the score should go up. For this we use the "touching?" block from the Sensing category and a loop from the Control category.

when green flag clicked
forever
  if <touching Star?> then
    change score by 1
    play sound "pop"
    hide

Every time the star is touched, the score variable goes up by 1. By showing the variable in the corner of the stage, we let the player see the score instantly.

Losing a life

Losing a life adds as much tension as gaining points. Say the character loses a life when it hits an obstacle.

when green flag clicked
forever
  if <touching Obstacle?> then
    change lives by -1
    go to starting position
    wait 1 seconds

The wait 1 seconds block matters: without it, the loop runs so fast during the single moment of contact that all lives are lost in one touch.

Moving between levels

Tracking the level with a variable

We keep the level in a variable too: level. The game starts at level 1. When the score reaches a certain number, we move to level 2.

In Scratch, different levels are usually shown with different backdrops. A backdrop is the background of the stage, changed with blocks from the Looks category.

Example: switch to the level 2 backdrop when the score reaches 10.

when green flag clicked
set level to 1
switch backdrop to "Level 1"
forever
  if <score = 10> then
    set level to 2
    switch backdrop to "Level 2"

Here, the moment score reaches 10, level becomes 2 and the background switches to the "Level 2" backdrop. The player can see they are now in a new stage.

Broadcasting a message to other sprites

Changing the backdrop may not be enough. In the second level maybe the enemy should behave differently too. For this we use the message blocks in the Events category. One sprite broadcasts a message, and others react when they hear it.

if <score = 10> then
  set level to 2
  switch backdrop to "Level 2"
  broadcast "level2-started"

Now the enemy sprite can listen for "level2-started" and speed itself up.

Increasing difficulty gradually

Tying speed to the level

A good game gets a little harder in every level. The simplest way is to tie the movement speed to the level variable. For example, let an enemy sprite move level steps each step:

when green flag clicked
forever
  move (2 * level) steps
  if on edge, bounce

In level 1 the enemy moves 2 steps per turn, in level 2 it moves 4. So the game speeds up as the level rises. By changing the numbers you can tune the difficulty yourself.

Increasing how often clones appear

In Scratch, a clone is a copy of a sprite. Falling stars or obstacles dropping from the sky are usually made with clones. Clones live in the Control category.

We can also tie how often clones are created to the level. If we shorten the waiting time, obstacles fall more often.

when green flag clicked
forever
  create clone of myself
  wait (2 / level) seconds

In level 1 a clone appears every two seconds, while in level 2 one appears every second. There are more obstacles on screen and the game gets harder. If you increase the number of clones too much the game becomes unplayable, so you have to find the balance by testing.

Ending the game

Every game should have an ending. There are usually two: losing when lives run out, and winning when the goal is reached.

when green flag clicked
forever
  if <lives = 0> then
    switch backdrop to "You Lost"
    stop all

The stop all block halts every script; the game freezes and the player sees the result. You can write a similar check for winning: for example, switching to the "You Won" backdrop when score = 30.

Hands-on mini task

Let's make a simple "collect the stars" game. Ingredients: a Cat sprite (the player), a Star sprite, and two backdrops.

  1. Create two variables named score and level.
  2. At the start of the game set score to 0 and level to 1, and switch to the "Level 1" backdrop.
  3. Move the Cat with the arrow keys.
  4. When it touches the Star, score goes up by 1 and the Star teleports to a random position.
  5. When score reaches 10, set level to 2 and switch to the "Level 2" backdrop.

Example script for the Star:

when green flag clicked
forever
  if <touching Cat?> then
    change score by 1
    go to random position

Run it and try this: when you get the score to 10, does the backdrop really change? Then replace score = 10 with score = 5 to make the level change easier. As you change the numbers, watch how the game changes.

Common mistakes

Forgetting to reset the variable

If you don't set score and lives at the start, your second play begins with the previous score. Always set the variables to their starting values when the green flag is clicked.

The "equals" trap in a fast loop

The block if <score = 10> is only true when the score is exactly 10. If the score jumps from 9 to 11 in one turn, this condition is never caught. A safer way is to use "greater than," like score > 9, or to set a marker once the level has changed.

Not limiting life loss

If a life is lost in every frame while the character touches the obstacle, all lives disappear in a single touch. After lowering a life, add a short wait block or move the character to a safe position.

Increasing difficulty too fast

Doubling the speed at every level makes the game unplayable within seconds. Increase difficulty in small steps and play the game yourself after each change.

Safety note

This lesson is done entirely on screen, inside Scratch; there is no electricity or hardware. Even so, a few things matter:

Lesson summary

Review questions

  1. Which Scratch structure do we use to store the score and lives in a game?
  2. Why do we need to reset the score variable at the start of the game?
  3. Which visual element is most often used to show different levels in Scratch?
  4. What are the two ways to increase difficulty covered in this lesson?
  5. How do we prevent all lives from disappearing at once when the character touches an obstacle?

Answers

  1. We use Variables; for example we create two variables named score and lives.
  2. If we don't reset it, the second play begins with the score left over from the previous game; we set the variable to its starting value so every game is fair and begins from the same point.
  3. Different backdrops are used; when the score reaches a certain number we switch to a new backdrop.
  4. Tying the movement speed to the level variable, and increasing how often clones are created (by shortening the wait time).
  5. After a life is lowered we add a short wait block or move the character to a safe starting position, so the same touch is not counted over and over.

Source and verification note

For “Score and Levels in Game Design”, verification focuses on whether the relationship between Score and lives with variables and Increasing the score remains consistent across examples. Block names are kept consistent with the current core Scratch categories. Project behaviour should be tested separately for start-up, normal play, errors and restarting.

Next lesson

Debugging and Testing: When our game doesn't work the way we expected, we learn to find and fix the mistake step by step.

Start QuizBack to Programming with Scratch
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.