Today we're going to make a fun, fully functional Snake Game using blocks like clone and if/then, with our Snake Scratch tutorial. Step-by-step we’ll take you behind the logic of the old classic Snake Game from Tetris and use Scratch coding to bring it to life. We'll also reveal how to customize it in unique ways to make it your own.
About the Snake Game
The snake game has been around for decades. It was originally played on a battery-operated hand-held device known to the world as Tetris. But unlike the game of Tetris, the Snake game was a little less eventful. However, the world still got hooked!
When the Snake game was first released, the focus was everything but the design. The “snake” was nothing more or less than a chain of grey blocks that got longer every time the snake was “fed”.
It’s food: grey blocks – much like the ones of its body. And because the snake had a mind of its own, the player had to keep the snake from self-destruction. As it moved without a break, the walls and snakes own body were its biggest threat. Turning the snake away from getting on edges kept you in the game. The upside of the challenge: higher levels that offered the snake a “wall” immunity. And so, we kept playing then, as we do now!
Today, the Snake game comes in all shapes and forms, as well as colors, but the basics of the game stay the same.
In this tutorial, we’re sticking with the original look and feel of the Snake game — so get ready to embrace square blocks. Our focus is to show you how easy it is to take something as plane as an image of a square and make it into a moving, eating, growing, functioning Snake. Check out the finished project here.
Snake Scratch tutorial step by step
In this tutorial, we will show you the core blocks you’ll need to put together in order to get your Snake Game running. Follow along as we simplify the flow.
1. Make a custom Scratch Sprite
Instead of selecting a Sprite from the Sprite library on Scratch, we will make our own. Hover over the icon for Sprite Library and select Paint to get started:
2. Draw a Square for your Snake Sprite
Click on the Rectangle tool to make a square. Click on the Fill (paint bucket icon) and then click inside your square to paint it one even color. Use Fill tool to choose your color.
3. Food Sprites
Right click on the Sprite you just created and select duplicate. Then, inside of the Costumes tab, make another copy of that Sprite. We will have two costumes for the Food Sprite, and then we’ll program it to switch between the two just like in the original Snake Game. Be sure to choose a different color for both costumes.
4. Make the Snake Move
Let’s program our Snake Sprite to get moving as soon as the game starts. Additionally, we’ll use up/down/left/right arrows to control Snake’s direction:
5. Clone for Length
We’ll first create a variable and then use it to keep track of how many times the Snake Sprite collides with the Food Sprite. Then we’ll use that same variable to control the length of the Snake. This will be done by deleting the clone after waiting so many seconds. The seconds become the value of the variable and the more the snake “eats” the longer it will take to delete the clones which makes the Snake Sprite bigger in length:
6. Set the Food Sprite’s Position and Function
Our Food Sprite will always go to a random position at the start of the game, as well as each time it collides with the Snake. It will also switch back and forth between the two costumes so that it appears as it is signaling the Snake to catch it at its new location. Lastly, we’ll keep track of its interaction with the Snake Sprite using our count variable:
7. Ending the Snake Game
Since the rule of the game is to keep the Snake Sprite away from the walls/edges, we’ll use an if/then conditional block along with the sensing block to check for the edge. The game stops if the condition is true:
You did it!
Remixes and examples of snake Scratch tutorial
There are numerous snake game remixes on Scratch. Most of them are customized but the concept is the same. For example, this Snake Game by Wodunne offers levels of difficulties and the snake itself resembles a real snake. Some game builders keep global scores such as this one made by FUNUT, where players all around the world can compete.
There are also some easy to follow YouTube tutorials like this one made by Daniel from Coder Prodigy, and this one by xamuil2 where a Pen Extension, My Block, and mouse pointer function is used to control the snake.
Now you know how to make a snake Scratch tutorial
In this tutorial, we showed you how to make a simple Snake Game on Scratch using clone blocks, variables, and arrow keys, in order to control snake’s behavior in the game. Want to learn more? Join us virtually at Create & Learn, where we offer the world’s best-in-class live STEM classes designed by Google and Stanford experts, including advanced Scratch, taught by experienced and passionate instructors.
Up next, find out how to make a game with levels on Scratch.
Written by Sandra Dizdarevic, a Create & Learn instructor with 6 years of experience teaching STEM to children in the 3rd through 11th grade. She has an Undergraduate as well as a Masters Degree in Management Information Systems from UNO.