- game dev
- open source
- javascript
Build your own Snake: 5 free GitHub projects
Code, art, sound and store publishing: 5 open source projects to remake Snake from scratch, with KAPLAY, TIC-80, Piskel, jsfxr and PWABuilder.

In this article
Snake is one of the simplest and most recognisable games ever made. The idea dates back to 1976 with Blockade, a two-player arcade game by Gremlin, and it became famous in the late 1990s, when Snake came preinstalled on the Nokia 6110.
The rules fit in one line: steer the snake, eat, grow longer and never hit yourself. That makes it the perfect first game to remake: small enough to finish, complete enough to touch every part of a real video game.
In this guide you will find 5 free, open source projects on GitHub, one for each part of the job: code, art, sound and publishing. At the end I explain how I made Quokkamotive, my own Snake with a train of quokkas.
Two paths
There are two ways to get to your Snake. The web path uses four tools, one for each part of the job. The all-in-one path uses a single program.
Web path
KAPLAY the code, in JavaScript
Piskel sprites and animations
jsfxr sound effects
PWABuilder the package for the stores
All-in-one path
TIC-80 code, sprites, maps and sound togetherIf you want to learn JavaScript and publish the game on the web and on the Play Store, take the web path. If you want a retro-flavoured game with everything in one place, take TIC-80.
How Snake works
Before the tools, the logic. It is the same in any language:
- The playfield is a grid, for example 20x20 cells.
- The snake is a list of cells, and the head is the first one.
- On every step you add a cell in front of the head, in the current direction, and remove the last one. If the head lands on the food you skip the removal, so the snake grows.
- If the head touches the body, the game is over. For the edges you choose: a wall, or leaving on one side and coming back on the other.
- The food reappears on a random free cell.
- To raise the difficulty, you shorten the time between one step and the next.
In JavaScript the heart of the game takes a few lines:
const COLS = 20, ROWS = 20;
let snake = [{ x: 5, y: 10 }, { x: 4, y: 10 }];
let dir = { x: 1, y: 0 };
let food = { x: 12, y: 10 };
function step() {
const head = {
x: (snake[0].x + dir.x + COLS) % COLS, // wrap to the opposite side
y: (snake[0].y + dir.y + ROWS) % ROWS,
};
if (snake.some(p => p.x === head.x && p.y === head.y)) return gameOver();
snake.unshift(head);
if (head.x === food.x && head.y === food.y) food = randomFreeCell();
else snake.pop();
}gameOver and randomFreeCell are yours to write: the first shows the end of the game, the second picks a cell the snake does not occupy. Everything else, drawing, input, sound and menus, is the job of the tools below.
01. KAPLAY: the code, in the browser
KAPLAY is a 2D game library for JavaScript and TypeScript. It calls itself "fun-first", meant to be enjoyable to use for beginners and experienced developers alike. It is open source under the MIT licence.
The quickest way to try it is KAPLAYGROUND, the online editor: you write code on the left and see the game on the right, with nothing to install. When you want a real project on your computer, npx create-kaplay my-game sets up the folder for you.
KAPLAY already gives you sprites, scenes, collisions and input handling, so for Snake you only need to write the grid logic shown above. The stable version is 3001.0.19, and the 4000 branch is being developed in parallel, still in alpha. The library comes from Kaboom.js: in the code the old kaboom() function has been replaced by kaplay(), and anyone coming from Kaboom will find the same way of working.
When to use it: if you want to learn JavaScript by making a game and then publish it on the web.
02. TIC-80: everything in one program
TIC-80 is a free, open source "fantasy computer", an imaginary computer made for creating, playing and sharing tiny games. It comes with every tool built in: code, sprite, map and sound editors, plus a command line.
You work within deliberate limits, like on old consoles: a 240x136 pixel screen, a 16 colour palette, 256 sprites of 8x8 pixels and 4 channel sound. They look like constraints, but for Snake they are perfect, and they push you to finish the game instead of polishing it forever.
You can code in Lua, JavaScript, Python, Ruby and other languages. The finished game is a "cartridge" file that runs on every supported platform, and you can share it on the community site, tic80.com/play. The current version is 1.4.1, under the MIT licence.
One thing to know: exporting the game without the editors, to publish it on app stores, is a feature of the PRO version. You can buy PRO on itch.io to support the project, or build it for free from the source code, as the README explains.
When to use it: if you want a retro game and do not want to jump between different programs.
03. Piskel: pixel art sprites and animations
Piskel is a pixel art sprite and animation editor that runs in the browser. It is open source under the Apache 2.0 licence, and there are also desktop builds for working offline.
You draw pixel by pixel, frame by frame, with a live preview of the animation as you work. When you are done, you export an animated GIF or a PNG sprite sheet, a single image with every frame laid out in rows and columns, the format game libraries load most easily.
For Snake you need only a few pieces: the head in four directions, the body, the corner and the food. Draw them all at the same size as the playfield cells, for example 16x16 pixels.
The last numbered release dates from 2018, but the online editor works and the repository still receives changes.
When to use it: for the game art, if you take the web path.
04. jsfxr: 8-bit sound effects in one click
jsfxr is the browser version of sfxr, the sound effect generator created by DrPetter. Open the page, press a button and you get a retro sound.
There are ready-made presets for the most common cases: Pickup/coin, Laser/shoot, Explosion, Powerup, Hit/hurt, Jump, Blip/select and Random. If a sound is almost right, you adjust the sliders until it is, then download it as a WAV. Developers can also use it as a library and generate sounds straight from code.
Snake needs three sounds: Pickup/coin when the snake eats, Hit/hurt for the crash and Blip/select for the menus. The project is released under the Unlicense, in the public domain.
When to use it: to give the game a voice in five minutes, without knowing how to compose.
05. PWABuilder: from the browser to the stores
PWABuilder is an open source project by Microsoft, under the MIT licence, that turns a web app into packages for app stores, including Google Play and the Microsoft Store.
The starting point is a PWA, an installable website: it must be served over HTTPS and have a manifest, the file that describes the app's name, icons and colours, and a service worker, the script that makes it work offline too. A game made with KAPLAY becomes a PWA once you add these two files.
For Android, PWABuilder generates a Trusted Web Activity: an app that opens your game full screen through the phone's browser, with no address bar. The last step is to publish the assetlinks.json file on your site, with the fingerprint of the key that signs the app, so Android knows the app and the site belong to the same person.
Before going to production on Google Play there is one requirement to know: personal developer accounts created after November 13, 2023 must run a closed test with at least 12 testers, opted in continuously for at least 14 days. I will cover the full process in an upcoming article.
When to use it: when the game works in the browser and you want it on the stores.
How I made Quokkamotive
Quokkamotive is my own Snake: Quash drives a train that grows longer as it picks up quokkas, across three eras, 1997, 2026 and 2142, with the same rules and the same speed. Only the style changes.
I wrote it without libraries, in a single HTML file: the graphics are drawn on the canvas and the sounds are generated in code with the Web Audio API. A few numbers, to show how little you need:
- a 13x11 grid, the same in every era;
- no walls: you leave on one side and come back on the other;
- the train starts with one step every 168 milliseconds and speeds up by 3.2 milliseconds per wagon, down to a minimum of 70;
- from the fourth wagon, blocks appear, stay put for a while and then vanish.
I used PWABuilder for the Android package. Before reaching the Play Store, Quokkamotive also has to go through the closed test.
If you are starting from scratch, I recommend the web path with KAPLAY: you get to a working game sooner, and Piskel and jsfxr give it your own art and sound.
Before you start
- You have picked a path: KAPLAY on the web or TIC-80 all in one.
- You have chosen the grid and the cell size, the same for the playfield and the sprites.
- You have decided what happens at the edges: a wall or wrapping to the opposite side.
- You have the three basic sounds: eating, crashing and menus.
- If you are aiming for the Play Store, the game is a PWA over HTTPS with a manifest and a service worker.
- If your Play account is personal and recent, you have 12 testers ready for the closed test.
Sources
Have a project in mind?
Hash42 Labs designs and builds web apps, websites and digital products for businesses, with security built in from day one. The same principles behind this article power Manji and Muni.
