top of page

Snake - A Classic Clone

The first project I completed independently without any tutorials was a clone of the classic Snake game in Unity. It's a straightforward project with an obvious goal, but, even in its simplicity, the project required a working knowledge of a library that implemented dynamic graphics rendering, a UI system, collision detection, and an integrated key-listener system that translates key presses into player movement. Unity offers a lot more than just these features, but for this project, they were more than enough.


The above photo depicts the starting state of the game inside the Unity editor. The UI is comprised of three text elements: ScoreText, GameText, and TimeText. The ScoreText keeps track of the number of "body" elements added to the Snake after a new pellet is absorbed. The GameText displays "Snake Clone" as the title while the game is being played, but switches to "Game Over. Press 'R' to restart" upon the player either colliding with the bounds of the board or the Snake's body. The TimeText displays the amount of time in seconds the game has been played over.


The game starts with the Snake body consisting of two elements. The green body-part is the head and the white body-part is the trailing part of the Snake. Upon collision with the red pellet, the length of the Snake is increased by one and the score is incremented by one as well. The placement of the pellets is randomly generated, and can appear anywhere on the board so long as a part of the Snake's body does not also occupy the same position.



As the game progresses, the body of the Snake will progressively grow longer until the snake's body fills the entire screen or until the player runs into itself or out of bounds.

Upon the termination of the game, the GameText changes and lets the player know they can start a new game by pressing the 'R' key. This resets the score and the timer and places the Snake back into its starting position.


To check out my repository with the code for this project, follow this link:

Comments


bottom of page