2023
Snake Game
The classic Snake game for the browser, written in plain JavaScript and drawn on an HTML canvas.
A personal project to practice JavaScript without any libraries or frameworks. The whole game is one script drawing to a 400 by 400 canvas on a 20 by 20 grid.
The game loop moves the snake, checks for collisions with the walls and with its own tail, and redraws the board each tick. Eating an apple grows the tail, plays a sound and adds to the score, and the game speeds up at 3 and again at 6 points.
Try it
This is the game exactly as it is in the repository. It needs a keyboard and plays sound.
- Click inside the game so it receives your key presses.
- Steer with W, A, S and D. The snake starts moving on your first key press.
- Eat the red apples to grow and score. Hitting a wall or your own tail ends the game.
- Press Restart game to play again.