In this part, we will make that every time the snake eats the food, its tail grows longer. Changes that we will introduce in this part reflected in this commit.
Let’s add a method that will handle intersection with food, and call it from the process.
If the center of the food is inside of the head segment, it means that there is an intersection. If this is the case, we take the tail tip segment to calculate a new position for the tail tip to make the snake one cell longer.
It is time to start saving the best score to local storage so that when the player visits the game next time, he could see his previous record.
In the GameManager, we start passing the best score to the render method of the view, we updating the best score after calling the process method.
Now we can open the web page and start hunting the food!
In the next part, we will complete the development of the game by adding logic that will restart the game when the player lost.
Reach the next level of focus and productivity with increaser.org.