Tutoring

Learn

Resources

How to Make a Snake Game on Scratch 3.0? – A Step-by-Step Tutorial on Scratch Games

Updated By

Reviewed By

How to Make a Snake Game on Scratch 3.0?
Image

Snake Game: Scratch games are visually fun and interactive ways of learning coding and game development, especially for children between the ages of 8 to 16. A Snake game on Scratch can be of different types depending on the sprite’s movement, objective, and rewards. In this blog, we will discuss how to code a Snake game on Scratch 3.0.


This is Chapter 2.4 in the
Scratch Game Tutorial


What is a snake game on Scratch?

A snake game is where you make a snake game on Scratch. In this Scratch game, we will be using the up/down/left/right arrow keys to move the snake. The Snake Game on Scratch will be created based on the following conditions:

  1. If Snake collides with the “food” sprite (a non-moving sprite), then the snake will grow.
  2. The game will end if the snake runs on the wall or touches the wall.

The detailed steps involved in creating this game on Scratch are explained below:

There are six following steps to make this game.

  1. Draw a square for your snake sprite
  2. Draw a food sprite
  3. Make the snake Move
  4. Draw the food sprite and  set the position & function
  5. Keep score
  6. Add game over

How to snake game on Scratch 3.0?

The detailed step-by-step process involved in making the Scratch snake game is explained below:

Step 1: Draw a square for your snake sprite on Scratch

  • Click on the “Costumes” option as shown in the image given below.
Click on the “Costumes” option
  • Delete the “costume2” as shown in the image given below.
Delete the “costume2”
  • Click on “Reshape” to reshape the Scratch.
Click on “Reshape”
  • Drag your mouse pointer over the car as shown below.
Drag your mouse pointer over the car
  • Drop the mouse pointer, and now the cat image is selected.
  • Press the “Delete” key or click on the “Delete” icon as shown below. 
Press the “Delete” key

Step 2: Draw a food sprite on Scratch for snake game

  • Click on “Fill” to choose a color.
Click on “Fill” to choose a color
  • Drag and adjust the “Color”, “Saturation”, and “Brightness” as shown below.
Drag and adjust the “Color”, “Saturation”, and “Brightness”
  • Click on the “circle” icon
Click on the “circle” icon
  • By dragging the mouse pointer over the paint area to draw a circle; the size could be any.
mouse pointer over the paint area
  • Drop the mouse pointer. 
  • Again click on “Circle” 
Again click on “Circle”
  • Select the color by adjusting the “Color”, “Saturation”, and “Brightness” as shown below
adjust the “Color”, “Saturation”, and “Brightness”
  • Drag the mouse pointer and draw a small circle within the green circle.
mouse pointer and draw a small circle within the green circle.

Step 3: Make the snake move in the Scratch game

  • Let’s control the snake using the up/down/left/right arrow keys in this game. The steps to do this are explained below:
make the snake move
  • Change the sprite name and name it “snake”. 
Change the sprite name and name it “snake”

Let’s add a backdrop to the game.

  • Click on the “Choose a Backdrop” icon as shown in the image given below.
Click on the “Choose a Backdrop” icon
  • Click on “Blue Sky 2”.
Click on “Blue Sky 2”
  • Backdrop added.
Backdrop added
  • Set the starting position of the snake. 
  • Drag & drop “when green flag clicked” & “go to x y”
  • Set the start position as (0, 0).
Set the start position as (0, 0)
  • Create a variable to store directions. 
  • Click on “Variables” and click on “Make a Variable”.
click on “Make a Variable”
  • Name your variable and click on “OK”.
click on “OK”
  • Drag & drop “set direction to” block and write value “right”.
“set direction to” block and write value “right”
  • Drag & drop the “when space key pressed” block as shown below.
  • Click on the dropdown and select “right arrow”.
Click on the dropdown and select “right arrow”
  • Similarly assign the direction for the left, up, and down. 
  • Drag & drop “when key pressed” and “set direction to” blocks as shown below.
Drag & drop “when key pressed” and “set direction to” blocks
  • Set the direction of the snake when the game starts. 
  • Drag & drop “set direction to” and set the direction right. 
Drag & drop “set direction to” and set the direction right
  • Add a conditional statement to check whether the right arrow key is pressed.
  • Drag & drop “if-then”.
Drag & drop “if-then”
  • Drag & drop the “equal to” operator as shown below. 
Drag & drop the “equal to” operator
  • Drag & drop the “direction” variable to the “equal to” operator as shown below.
  • Write the “right” to “equal to” operator.
Write the “right” to “equal to” operator
  • Change the snake’s x position to a positive value so that the snake can move in the right direction when you press the right arrow key.
  • Drag & drop the “change x by” block as shown below.
Drag & drop the “change x by” block
  • Put the conditional statement in a “forever” loop, checking it each time.
“forever” loop,
  • Click on the “green flag”.
  • The snake can move in the right direction by pressing the right arrow key.
snake move in the right direction
  • Similarly, add another conditional statement for the “left” arrow key.
  • Drag & drop “if-then”, “equal to” and “direction” variables as shown below.
  • To move the snake in the left direction change the snake x position value with a negative number.
  • Drag & drop the “change x by -5” block as shown below.
Drag & drop the “change x by -5” block
  • Similarly, add another conditional statement for the “up” arrow key.
  • Drag & drop “if-then”, “equal to” and “direction” variables as shown below.
  • To move the snake in the up direction change the snake y position value with a positive number.
  • Drag & drop the “change y by 5” block as shown below.
Drag & drop the “change y by 5” block
  • Similarly, add another conditional statement for the “down” arrow key.
  • Drag & drop “if-then”, “equal to” and “direction” variables as shown below.
  • To move the snake in the up direction change the snake y negative value with a positive number.
  • Drag & drop the “change y by -5” block as shown below.
Drag & drop the “change y by -5” block
  • Click on the “green flag”.
  • Snake can move in left/right/up/down direction using left/right/up/down keys. 
Click on the "green flag"

Let’s add some effects so that the snake sprite mimics a snake. 

  • Drag & drop the “create clone of myself” block as shown below.
  • Click on the “green flag”.
  • Snake can move in left/right/up/down direction using left/right/up/down keys and its length is increasing but we do not want to increase length automatically.
Click on the "green flag"
  • Let’s program the clone of the snake.
  • Drag & drop the “when I start as a clone”, and “wait seconds” blocks as shown below.
  • Set the wait time at 0.1, you can choose any; please note this wait time will decide the length of the snake.
  • Drag & drop the “delete this clone” block as shown below.
Drag & drop the “delete this clone” block
  • Click on the “green flag”.
  • Snake can move in left/right/up/down direction using left/right/up/down keys and its length is not increasing automatically.
Click on the "green flag"

Step 4: Draw the food sprite and set the position and function

  • Click on “Paint”
Click on “Paint”
  • Click on “Fill” and select your color.
Click on “Fill” and select your color
  • Click on the “Circle” icon of the scratch paint tool.
Click on the “Circle” icon
  • Drag the mouse pointer over the paint area and create a circle.
create a circle
  • Add outline to food sprite.
  • Click on “Outline”
Click on “Outline”
  • Select your outline color.
Select your outline color
  • Click on “Reshape” to select it then click on the “red circle”.
click on the “red circle”
  • Set the outline thickness to five.
Set the outline thickness to five
  • Change the design of the “red circle” so that it looks like foody stuff by dragging the outline.
Change the design of the “red circle”
  • Click on fill and select color, then click on “circle”
  • Drag the mouse pointer over the “red circle” and draw a small circle within the “red circle”
click on “circle”
  • Let’s code the food sprite and set its position and functions.
  • Click on “Code”
Click on “Code”
  • Change the food sprite name and size. 
Change the food sprite name and size
  • Set the start position of the food sprite. 
  • Drag & drop “when green flag clicked” and “go to x y” blocks as shown below.
Drag & drop “when green flag clicked”
  • X, Y value of scratch stage. 
  • X value range is from -240 (left) to 240 (right).
  • Y value range is from 180 (up) to -180 (down).
X, Y value of scratch stage
  • Make the position random by using the “pick random to” block.
  • Drag & drop “pick random to” block to x and y and set its value,
  • And set the x value from -240 to 240 & y value from 180 to -180 as shown below. 
set the x value from -240 to 240
  • Write a conditional statement to check whether the food sprite touches the snake sprite. 
  • Drag & drop “if-then” and “touching” blocks as shown below, click on “dropdown” and select “snake”.
Drag & drop “if-then” and “touching” blocks
  • If the snake touches (eat) the food then change its position to a random position. 
  • Drag & drop the “go to x y” and “pick random” blocks as shown below. 
  • And set the x value from -240 to 240 & y value from 180 to -180 as shown below. 
set the x value from -240 to 240
  • Put the above conditional statement into the “forever” loop.
“forever” loop
  • Click on the “green flag”.
  • The snake can eat the food, and then the food changes its position to a random place.
Click on the "green flag"
  • Now, let’s increase the snake length when the snake touches the food sprite. 
  • Create a variable, click on “Variables” and, then click on “Make a Variable”.
click on “Make a Variable”
  • Name the variable then click on “OK”.
click on “OK”
  • Click on the “snake” sprite.
Click on the “snake” sprite
  • Drag & drop the “length” variable to the “wait seconds” block as shown below.
Drag & drop the “length” variable to the “wait seconds” block
  • Change the “length” variable when the snake touches the food. 
  • So, first, click on the “food” sprite.
click on the “food” sprite
  • Drag & drop the “change direction by” block as shown below.
  • Click on the “length” 
Click on the “length”
  • Change the “change length by” value by 0.1 when “snake” touches the “food” sprite. 
“snake” touches the “food” sprite
  • Click on the “green flag”.
  • Now, snake length increase by 0.1 when it touches the food.
Click on the "green flag"

Step 5: Add score to the snake game

Let’s add a score in the game when the snake touches the food.

  • To keep track of scores create a variable. 
  • Click on “Variables” and, then click on “Make a Variable”
click on “Make a Variable”
  • Name the variable then click on “OK”.
click on “OK”
  • Drag & drop the “change direction by” block as shown below. 
  • Click on the dropdown and select “score”.
select “score”
  • Change the score variable value by 10.
Change the score variable value by 10
  • Click on the “green flag”.
  • Now, the score increase by 10 when the snake touches the food. 
Click on the "green flag"
  • Let’s set the snake length & the score to zero when the game starts.  
  • Click on the “snake” sprite.
Click on the “snake” sprite
  • Drag & drop “set the score to” and “set length to” blocks as shown below.
Drag & drop “set the score to” and “set length to” blocks
  • Click on the “green flag”.
  • Now, length and score start with zero when the game starts.

Step 6: Add a game-over message

Let’s add game-over features to the game; if the snake touches the edge of the scratch stage, the game will be over. 

  • Add a conditional statement to check whether the snake touches the edge of the scratch stage.
edge of the scratch stage
  • Drag & drop “say for seconds” block and set the game over message.
Drag & drop “say for seconds” block
  • Drag & drop the “stop all” block as shown below.
Drag & drop the “stop all” block
  • Put the conditional statement into the “forever” loop.
  • Drag & drop the “when green flag clicked” block on top as shown below.
Drag & drop the “when green flag clicked” block
  • Click on the “green flag”.
  • Now, if the snake touches the scratch stage edge then the game stops and displays the game-over message. 
Click on the "green flag"

Congratulations, You have completed the Snake game in Scratch.

Snake game code in Scratch?

The scratch game code for both snake and the food sprite are explained below:

Snake game code for snake sprite

Snake game code for snake sprite

Snake game code for food sprite

Snake game code for food sprite

Time to Play!

  • Congratulations, You have completed the Snake game in Scratch!
  • Click on “green flag” to start playing the Snake game. What are the enhancements to the game you can think of? Do let us know in the comments section below.

How to create a snake game on Scratch?
Follow the steps given below to create a snake game on SCratch:

  1. Draw a square for your snake sprite
  2. Draw a food sprite
  3. Make the snake Move
  4. Draw the food sprite and  set the position & function
  5. Keep score
  6. Add game over

What is the easiest game on Scratch?
The maze game can be considered an easy game to make on Scratch. The user needs to navigate the sprite through a complicated maze while avoiding the maze boundary and different sudden obstacles.

What is the most popular game on Scratch?
The most popular game on Scratch is Paper Minecraft v11.6 (Minecraft 2D). It has over 35000 hearts.

We hope this detailed article on how to create a Snake Game on Scratch is helpful to you. Do try creating this game on Scratch and let us know if it worked for you on Scratch. Also, if you have any queries regarding this game, then ping us through the comment box below and we will be happy to assist you. 

Want to make more such games? Check out our beginner-friendly guide to Scratch games.

Get 1-on-1 online Scratch classes
Don't forget to share this post!
tutor Pic
tutor Pic