overview

Snake++ is a re-implementation of the classic Snake game in C++ without the use of any libraries except X11 (on Linux) and Win32 (on Windows) for graphics. The game features a few different power-ups that can be collected by the snake to change its behavior. Additionally, it includes enemies and obstacles that the player must avoid.

This project is based on a school project which can be found here. While it is based on the same concept, this project is a complete re-write and underlying game logic has been changed to allow for more features.

gameplay

The game is controlled using the arrow keys. The snake will move in the direction of the last arrow key pressed. Below are the different power-ups that can be collected by the snake.

Food increases the length of the snake and is the colour purple.

Portal power-up allows the snake to go through one side of the screen and come out the other side. It is the colour blue.

Attack power-up allows the snake to eat exactly one ghost. It is the colour red.

Rainbow power-up is a combination of all the power-ups and appears multiple shades of orange. The effect has a time limit and will be de-applied after the time limit is reached. Time limit is shown in the bottom UI bar.

Ghosts randomly spawn and wander around the screen. If the snake collides with a ghost when it does not have the attack power-up, the snake is reset to its starting length and score resets to 0. The game ends when the snake runs out of lives.

The game also features some other collectibles such as stars and hearts which increase the score and lives respectively.

technical_improvements

Some technical improvements over the original project are below.

An interval API was implemented to allow for more control over timing during the game loop. It leveraged C++ lambda functions to allow for easy implementation of custom intervals.

An entity class was implemented to allow for easy creation of game objects. It used virtual dispatch to allow all entities to be updated and rendered in a generic way. The entity class also allowed for easy creation of new entities by extending the class.

All sprites and font characters are represented as a 64-bit integer to be rendered as 8x8 pixel sprites. This is an improvement over the old version which used a 2D array of characters to represent sprites.

images

Below are some images of the game in action.

Snake++ start screen Snake++ normal snake Snake++ attack snake Snake++ portal snake Snake++ rainbow snake Snake++ game over screen