Archive

Snake

p5.js · The first game I finished

Controls

Arrow keys to steer. Eat, grow, avoid yourself.

How it works

The snake is an array of grid coordinates. Each tick a new head is pushed in the current direction and the tail is popped — unless food was just eaten, in which case the tail stays and the body grows by one.

Collision is a lookup: does the new head coordinate already appear in the body, or has it left the board? That is the entire game. Building it was the moment classic arcade games stopped feeling like magic.