← How a game is made: Daily Challenge's Snake
Coding Snake, part 1: the code
This is the video's code, as is: a playable Snake in JavaScript, with no engine or libraries. The names and the logic are those of Daily Challenge's Snake. What's missing (the maps with walls, the bonus bug, the hunger, the sound and the server) is part 2.
The video
Play it here
With the keyboard's arrows or with the buttons. It's the same code as below.
Copy it
Each tab is one of the video's files. All in one is the same program in a single file.
<!doctype html>
<style>
canvas {
width: 480px;
image-rendering: pixelated;
}
</style>
<canvas></canvas>
<script type="module" src="main.js"></script>
$ npx serve
→ http://localhost:3000
How to run it on your computer
- The easy way: copy "All in one", save it as
snake.htmland double-click it. - As in the video: save the files, each with its own name, in one folder. Modules don't open with a double click: in that folder run
npx serve(orpython3 -m http.server) and open the address it gives you (with Python it'shttp://localhost:8000).