18 Jul 2016

Snake

An interactive snake game

Overview

There are times when a student begins a coding project and the end-goal turns out to be absolutely worthless, and admittedly this is one of posts. I wanted to replicate a complete game from scratch (menus, high scores, user-interactions, and a purpose), but a Snake game is not that much fun to play anymore! However, the Snake project, which was inspired by slither.io combined with the game from the late 70s, was fun to make and a great learning experience. The game is simple: eat food and grow, but do not run in to the wall or cross over yourself. The program was coded from scratch with C++ and the SFML libraries for drawing primitive shapes and basic event-handling (e.g. hitting a letter on the keyboard), and includes the following:

  1. a menu framework including high scores and a screen for the player to type the name
  2. a snake made out of overlapping circles in an alternating rainbow pattern
  3. randomly placed food of varying sizes (larger sizes increase the score/snake more) and the food moves in a circular path of some random radius to make it more difficult
  4. a point system based on food consumption
  5. the snake is controlled by the arrows, and may be accelerated to larger speeds with the space-bar
  6. when the snake hits the wall or itself (which requires simple collision detection), a death method is invoked which includes increasing the radii of the circles making up the snake.

The game is silly, obviously, and I probably could not even get my 5 year old nephew to play this even if I paid him… BUT this was the first game and it was important to finish what I started. Making the game more advanced, e.g. adding other competing snakes with some automation, is now simply a matter of investing more time. See the figure for some screen shots of the menus, game, and death.

-->