May 2, 2014
Schnake! is a modified clone of the classic game Snake, beloved by many a fan of old-school video games. The goal of snake is simple - "eat" as many of the apples that appear on the screen as you can so that your snake can grow. Don't run into your body or off the screen though, or it's game over for you!
- Recursion was used to determine the length of the snake body and detect collisions
- Lists and consing to them were used to build the snake progressively
- A world state that kept track of the position, direction, and status of all objects in the game
- Higher order procedures were used so that functions could be accepted as arguments to manipulate the world
- Abstraction was used throughout the GUI and world creation
This game makes use of the How to Design Programs packs that come with a Racket installation. Specifically, I needed the htdp/world and htdp/image packs to handle world creation for the game and to allow direct insertion of graphics into the code. I also used the lang/posn library to keep track of the positions of the snake and apples.
The game is a basic rendition of Snake, so there is nothing particularly new about it that hasn't been seen in other versions. However, because the nature of Racket allows very simple and streamlined code, the game would be very easy to expand or be used as a template for other future games. Parameters are also easily swappable, so tiles can be enlarged or shrunk and the framerate can be slowed or sped up to change the difficulty of the game. Additionally, I found it interesting that you can directly insert images into the code for direct access by the program, so I can easily change the background, end of game screen and even the image of the apple when I want.
Technology Used Block Diagram
My initial project was actually intended to be a clone of the now-popular game, 2048. I started working on getting the Racket GUI libraries to work and then tried to figure out how to detect when two tiles collided (an important component of 2048). Tile collision proved to be easy; generating multiple random tiles, tracking multiple collisions at once, and keeping score, however, did not. Instead of giving up, I decided to take what I knew worked with the collision detection and clone another popular game, and thus Schnake was born. When I have more time over the summer though, I plan on using this code as a base to complete my initial project plan and finish my 2048 clone too.