How to make a snake game
Snake is the classic first coding project because the whole game is a grid and a list. The head moves one cell, the tail follows, food makes it longer and touching yourself ends the run.
How Snake works
Snake became famous on Nokia phones from 1997, starting with the Nokia 6110. Every version uses the same few parts.
- The grid. The board is a grid of cells, for example 20 by 20. Everything moves one cell per tick.
- The body is a list. Each tick, add a new head in the direction of travel and remove the last tail piece. If the snake just ate, skip the removal and it grows.
- Food. Place it on a random empty cell. Check it is not under the snake.
- Collision. Game over if the head hits a wall or any part of the body.
- Speed. Shorten the tick a little every few apples so the game gets harder.
Code it in Python
- 1. Set up. Install Python and the pygame library with pip install pygame. Python's built-in turtle module also works for a simpler version.
- 2. Game loop. Each frame: read keys, move the snake, check collisions, draw, then wait with a clock tick.
- 3. Direction. Arrow keys change direction, but ignore a key that would reverse the snake into itself.
- 4. Draw. Draw each body cell and the food as squares. Show the score at the top.
- 5. Game over. Show the score and restart on a key press. Fast restarts keep people playing.
Twists worth trying
- Arena. Many snakes, one big map, eat the ones that crash. Slither.io (Steve Howse, 2016) made this an .io hit.
- Puzzle snake. No timer, fixed levels, the snake's length is the puzzle. Snakebird (Noumenon Games, 2015) is the reference.
- Two heads. Two players on one board, or one snake you steer from both ends.
Snake without code
If you want the game more than the coding exercise, describe it to Roam, a free iPhone app: arena, theme, what the snake eats. It comes back playable, and you can play it with friends.
Play it on Roam
Create your snake game with Roam
Pick the arena and the twist. Play it on your iPhone, then say what to change.
Try: "neon snake arena, eat glowing orbs to grow, boost costs length, my friends are the other snakes"Questions people ask
How long does it take to code Snake in Python?
A beginner following a tutorial can usually finish a basic version in an afternoon. Menus, sound and high scores take longer.
What is the best language to code a snake game?
Python with pygame is the most common choice for beginners. JavaScript with an HTML canvas is a close second.
Can I make a snake game without coding?
Yes. Scratch uses blocks instead of text, and Roam builds a playable snake game from a sentence on iPhone.
Keep exploring
- How to make a small game you will actually finish
- How to make a 2D game
- How to make a game on your phone
- How to make a game on iPhone
- How to make a horror game that actually scares people
- How to make a game for free
More on Roam: All Roam games Games to play, by kind

