What you need
Complete the setup, drawing, game loop, input, collision, and state lessons first.
This project joins the beginner lessons into one playable loop: input changes direction, each tick moves the snake, food adds score, and a self-hit ends the run.
Use the arrow keys, then choose Restart after a game over.
Complete the setup, drawing, game loop, input, collision, and state lessons first.
How a small state object turns several separate game ideas into a complete playable rule set.
Do not allow an immediate reversal into the snake’s neck, and reset both the body and direction when restarting.
Snake is a good first complete project because the rules are visible and small. It is not a replacement for a larger project architecture once the number of entities and levels grows.
Compare this mini version with the playable Snake game, then return to the beginner route to review any missing step.
Canvas drawing and animation concepts are based on MDN’s Canvas tutorial. Updated 2026-07-14; the mini game was checked locally with keyboard input and restart.