This page is part of the Snake in MIT Scratch Tutorial.
Before work begins on programming or art for the game it is a good idea to write out a design document that details what features the game will have. This design document can act as a road map when implementing the game. Many important decisions about how the game will work are easier to make on pen and paper than within the Scratch interface.
Features of the Snake Game
This section of the tutorial gives a brief introduction to all the features of the final game. The theory and scratch implementation of each feature is described throughout the later chapters of the tutorial.
Feature 01 – Playing Area is Divided into a Grid
The usual Scratch playing area will be divided into a grid of large squares. Each square will hold one piece of the snake or one apple.
The default stage size of the Scratch player is 480×360. We can Divide this into squares of 40×40 pixels giving us a grid size of 12×9 for our snake to move in.
Feature 02 – Onscreen Snake with a Segmented Body
The snake is composed of individual pieces. Each of these occupies one square on the grid and can be arranged to give the impression of the snake moving through the grid.
Feature 03 – Snake Moves at Regular Intervals
At a regular interval the snake moves ahead according to the direction it is facing.
This adds some pressure on the player as they have to decide where to move before the snake crashes.
The snake’s head leads the way and its tail follows.
Throughout the game the snake’s movement speed does not change.
Feature 04 – Using the Arrow Keys to Control the Snake
The player is able to use the arrow keys to change the direction the snake is moving.
The snake can only turn at right angles. When it is facing up it can turn right or left and when it is facing right it can turn up or down.
When the snake changes direction it should move immediately.
It is important that the direction of the input is checked so that the snake cannot move back on itself.
Feature 05 – Snake Gets Longer When it Eats an Apple
The snake gets longer when it eats an apple.
The player scores a point when they eat an apple.
The objective of the game is to eat apples until the snake grows so long it fills the screen.
The animation below illustrates how the snake grows:
Pay attention to the frame directly after the snake eats the apple. The head advances one square but the tail stays where it is. By moving the head forward but not the tail the snake gets longer.
Feature 06 – Game Over if the Snake Eats its Tail
If the snake’s head crashes into the snake’s body then the game is over.
The game should pause for a moment and let the player see the final state of their snake before moving on to the game over screen.
Feature 07 – If the Snake Moves off the Edge of the Playing Area it Appears on the Opposite Side
When the snake’s head moves through the side of the screen it should appear the other side.
Instead of crashing into the side of the screen the snake can wrap itself several times around the screen.
Feature 08 – Apples Spawn in a Random Location
When the snake eats an apple a new one should spawn in a random location on the grid.
Apples should not spawn on a cell currently occupied by the snake.
If the snake covers the entire map then an apple should not spawn.
Feature 09 – The Scenes that Compose the Game
The game is composed of the following scenes:
- Title Screen – This screen is shown when the game starts. It has a brief explanation of the controls and says ‘Press Space to Start’.
- Game Screen – All the gameplay with the snake happens on this screen.
- Lose Screen – If the snake crashes into itself this game over screen will be shown. It has a message ‘Press Space to Try Again’.
- Win Screen – If the player manages to grow the snake to fill the entire screen without crashing then this screen is shown.
Feature 10 – Sounds that Play During the Game
The game will have the following sound effects:
- Apple Collect – A nice chime when a player collects and apple and scores a point.
- Crash – A harsh sound that plays when the snake crashes into itself.
- Movement Sounds – A two-toned beep will play as the snake moves.
- Applause – Victory is celebrated with the sound of clapping and cheering.
This section of the tutorial has specified all of the features that the final game will contain.
Later sections detail how each of these features are implemented using Scratch.
Next Section: Implementing the Game in Scratch