Examples Snake

Snake

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: Created by Prashant Gupta. Revised by Caleb Foss. From 2024 onwards, edited and maintained by p5.js Contributors and Processing Foundation. Licensed under CC BY-NC-SA 4.0.

You can find the code history of these examples here: 2023 code, 2023 code. You can suggest improvements by contributing to the current website!