Looking for a quick challenge of your game design skills? Let’s build snake! Snake is a simple game where you play as a snake who needs to hunt down and eat dots to get bigger, but if the snake runs into a wall its game over

Creating a sprite

  • Go to the draw sprite menu and create a square
  • You can create any design you like for your snake, the pattern will repeat so think about how it will look as it gets longer

Setting up the snake

  • When the game starts lets centre our snake
  • We’ll also add keys to control the 4 directions of our snake
  • Lastly add a rule that If the snake touches the edge the game stops

Let’s get the snake some food

  • Create a sprite you think your snake would like to eat
  • Let’s make use of the go to random position block to get the food to spawn at random
  • If the food spawns on the edge it isn’t fair since the snake can’t touch the edge so we’ll find a new position for it
  • We can also find a fun sound to play when the snake eats the food

Creating a score

  • If you’ve worked through some other tutorials you might be a pro at scores but heres a quick reminder
  • We’ll create a variable called “Score”
  • Under the snake sprite when the game starts, score is set to 0
  • Going back to the food sprite, if it is touching the snake it will increase the score by 1

Lets test the game

  • Can you move the snake correctly?
  • Can you eat the food?
  • Does hitting a wall stop gameplay?

Let’s make the snake grow

  • Create a variable called clone length
  • Set it equal to 0.3
  • In the forever loop, create a clone of self
  • Add a condition “When I start as clone”
  • we’ll wait “Clone Length” seconds before deleting the clone
  • Jump back over to the food sprite
  • in the touching snake condition, we’ll want to change the clone length by 0.2
  • These variable numbers can be changed, but it seems really small numbers make the movement look the best

Give the snake a head

  • If you want the snake to look more like a snake, lets give it a head
  • Go to draw sprite and create a matching head for your body design
  • Copy the code from the body sprite and remove the parts about clones, we don’t want a hydra on our hands
  • Add in a Go To Front Layer block from the looks panel to ensure the snake head is above the body

Test the game

  • Does everything move as it should?
  • Are you happy with your design?
  • Any changes you’d like to make to make it even better?
  • Once you’re happy with your game have a friend try it. Use two stars and a wish to see what works well and what could be even better
  • Make sure to add instructions and publish your game to share your creativity with the world!
Congratulations! You’ve mastered another classic arcade game! If you can wrangle snake on scratch, who’s to say you can’t dominate Python next! The world of coding is your oyster!