Snake Game

System Design

Using P5js to design a sustem that would simulate an existing natural events.


This project is a snake game. The body of the snake is randomly colored. The foods will appear randomly and disappear within every 5 seconds. 
Use the keypress up down left right to control the direction of the snake movement.

Try Game = function(pos){
  var d = dist(this.x, this.y, pos.x, pos.y);
  if (d<1){;
  print("FOOD EATEN");
  return true;
  return false;

Food Eaten

After snake eat the food, there will be a prompt of the amount of food that has been eaten.

Snake Eyes

I first determine the size of the snake's head and then calculate the position of the eyes based on the x and y of the snake's head. This ensures that the eyes follow when the head moves.

Coding Works