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

Contents
child creating a Scratch project

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.
scratch sprite
  • Delete the “costume2” as shown in the image given below.
scratch sprite
  • Click on “Reshape” to reshape the Scratch.
scratch sprite
  • Drag your mouse pointer over the car as shown below.
scratch sprite
  • Drop the mouse pointer, and now the cat image is selected.
  • Press the “Delete” key or click on the “Delete” icon as shown below. 
scratch sprite

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

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

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:

snake game on scratch
  • Change the sprite name and name it “snake”. 
snake game on scratch

Let’s add a backdrop to the game.

  • Click on the “Choose a Backdrop” icon as shown in the image given below.
scratch backdrop
  • Click on “Blue Sky 2”.
scratch backdrop
  • Backdrop added.
scratch backdrop
  • Set the starting position of the snake. 
  • Drag & drop “when green flag clicked” & “go to x y”
  • Set the start position as (0, 0).
snake game on scratch
  • Create a variable to store directions. 
  • Click on “Variables” and click on “Make a Variable”.
snake game on scratch
  • Name your variable and click on “OK”.
snake game on scratch
  • Drag & drop “set direction to” block and write value “right”.
snake game on scratch
  • Drag & drop the “when space key pressed” block as shown below.
  • Click on the dropdown and select “right arrow”.
snake game on scratch
  • Similarly assign the direction for the left, up, and down. 
  • Drag & drop “when key pressed” and “set direction to” blocks as shown below.
snake game on scratch
  • Set the direction of the snake when the game starts. 
  • Drag & drop “set direction to” and set the direction right. 
snake game on scratch
  • Add a conditional statement to check whether the right arrow key is pressed.
  • Drag & drop “if-then”.
snake game on scratch
  • Drag & drop the “equal to” operator as shown below. 
snake game on scratch
  • Drag & drop the “direction” variable to the “equal to” operator as shown below.
  • Write the “right” to “equal to” operator.
snake game on scratch
  • 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.
snake game on scratch
  • Put the conditional statement in a “forever” loop, checking it each time.
snake game on scratch
  • Click on
  • The snake can move in the right direction by pressing the right arrow key.
snake game on scratch
  • 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.
snake game on scratch
  • 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.
snake game on scratch
  • 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.
snake game on scratch
  • Click on
  • Snake can move in left/right/up/down direction using left/right/up/down keys. 
snake game on scratch

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

  • Drag & drop the “create clone of myself” block as shown below.
snake game on scratch
  • Click on
  • 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.
snake game on scratch
  • 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.
snake game on scratch
  • Click on
  • Snake can move in left/right/up/down direction using left/right/up/down keys and its length is not increasing automatically.
snake game on scratch

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

  • Click on “Paint”
snake game on scratch
  • Click on “Fill” and select your color.
snake game on scratch
  • Click on the “Circle” icon of the scratch paint tool.
snake game on scratch
  • Drag the mouse pointer over the paint area and create a circle.
snake game on scratch
  • Add outline to food sprite.
  • Click on “Outline”
snake game on scratch
  • Select your outline color.
snake game on scratch
  • Click on “Reshape” to select it then click on the “red circle”.
snake game on scratch
  • Set the outline thickness to five.
snake game on scratch
  • Change the design of the “red circle” so that it looks like foody stuff by dragging the outline.
snake game on scratch
  • 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”
snake game on scratch
  • Let’s code the food sprite and set its position and functions.
  • Click on “Code”
snake game on scratch
  • Change the food sprite name and size. 
snake game on scratch
  • Set the start position of the food sprite. 
  • Drag & drop “when green flag clicked” and “go to x y” blocks as shown below.
snake game on scratch
  • 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).
snake game on scratch
  • 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. 
snake game on scratch
  • 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”.
snake game on scratch
  • 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. 
snake game on scratch
  • Put the above conditional statement into the “forever” loop.
snake game on scratch
  • Click on
  • The snake can eat the food, and then the food changes its position to a random place.
snake game on scratch
  • 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”.
snake game on scratch
  • Name the variable then click on “OK”.
snake game on scratch
  • Click on the “snake” sprite.
snake game on scratch
  • Drag & drop the “length” variable to the “wait seconds” block as shown below.
snake game on scratch
  • Change the “length” variable when the snake touches the food. 
  • So, first, click on the “food” sprite.
snake game on scratch
  • Drag & drop the “change direction by” block as shown below.
  • Click on the “length” 
snake game on scratch
  • Change the “change length by” value by 0.1 when “snake” touches the “food” sprite. 
snake game on scratch
  • Click on
  • Now, snake length increase by 0.1 when it touches the food.
snake game on scratch

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”
snake game on scratch
  • Name the variable then click on “OK”.
snake game on scratch
  • Drag & drop the “change direction by” block as shown below. 
  • Click on the dropdown and select “score”.
snake game on scratch
  • Change the score variable value by 10.
  • Click on
  • Now, the score increase by 10 when the snake touches the food. 
snake game on scratch
  • Let’s set the snake length & the score to zero when the game starts.  
  • Click on the “snake” sprite.
snake game on scratch
  • Drag & drop “set the score to” and “set length to” blocks as shown below.
snake game on scratch
  • Click on
  • Now, length and score start with zero when the game starts.
snake game on scratch

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.
snake game on scratch
  • Drag & drop “say for seconds” block and set the game over message.
  • Drag & drop the “stop all” block as shown below.
snake game on scratch
  • Put the conditional statement into the “forever” loop.
  • Drag & drop the “when green flag clicked” block on top as shown below.
snake game on scratch
  • Click on
  • Now, if the snake touches the scratch stage edge then the game stops and displays the game-over message. 
snake game on scratch

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 in scratch

Snake game code for food sprite

snake game code in scratch

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

Related Posts

Company

Contact

Email:

info@wiingy.com

+(1) 618-827-5802

About Wiingy

Wiingy provides 1-to-1 online tutoring, instructor-led online technology courses, and web tutorials to school students, university students, and working professionals across the globe.

Wiingy works with top verified, qualified, and experienced instructors to deliver online lessons in Coding, Math, Science, and over 50 other subjects.

Parents and students have rated the teaching experience as 4.8/5 and above.

We are a community of over 20,000 students across 10+ countries growing daily.

Copyright Wiingy Pvt Ltd © 2021. All Rights Reserved

Do you want to learn from
Verified, Qualified, and Experience Online Tutors
backed by Wiingy's Perfect Match Guarantee?