This is a reproduction of a type of arcade game called Snake. The first Snake game was Blockade, released in 1976, and many games use the same structure. In Snake games, the player controls the movements of a snake, represented in this example by a green line. The player’s goal is to collide the snake with a fruit, represented by a red dot. Each time the snake collides with a fruit, the snake grows longer. The player’s goal is grow the snake as long as possible without colliding the snake into itself or into the edges of the play area.
This example uses an array of vectors to store the positions of each of the segments of the snake. The arrow keys control the snake’s movement.
Snake by p5.js Contributors and the Processing Foundation is licensed under CC BY-NC-SA 4.0.
Related Examples

Large purple circle on a grey background.
Circle Clicker
Make a game about clicking a circle quickly and save the high score.

Two narrow white rectangles and a white square representing the paddles and ball in a game of ping pong.
Ping Pong
Make a game inspired by Atari's Pong.

A narrow green L shape and a red square representing the snake and fruit in the arcade game Snake.
Snake
Make a game based on Snake arcade games.