3D Snake by Austin Munsch

Image 1: Near the start of a game.

My final project for CPE 471 was to create a game of Snake in 3D. There's a 2D grid for the board and an array for the current snake. Apples are placed in a random spot on the board and the snake can be controlled to eat the apple. Each apple increases the length of the snake by one and gains you a point. If you hit your own tail or run off the edge of the map, you lose and it tells you your score.

I started out by writing all of the game logic from scratch. I made the game board print out to the screen with ASCII characters for the different elements. Once I got all the basic logic for the game working, I started working on making objects show up in the scene and doing it in 3D. I added a ground plane for the playing field, cubes for the pieces of the snake, and a sphere for the food. Originally I had intended to let the player control the camera and move around to view the playing field from different angles. After I added that functionality and tried it out myself, I found it was far too confusing for you to try to control the snake from an odd camera angle, so I scrapped that feature and started working on other stuff.

Image 2: rendered font

Next I wanted a scoreboard to show up so you could keep track of how many apples you had eaten (aside from just looking at the length of the snake). This is probably the smallest feature that took the longest time to implement, as I had no problem keeping track of the score, but it was extremely hard to render it to the screen. All the examples I found online used a function called glutBitmapString() which only works on FreeGlut, not the version we were using. I eventually stumbled across a function named glutBitmapCharacter() which would render letters to the screen character by character. After messing with the parameters for about an hour, I got it to work and I was able to display instructions along with the score along the top of the screen.

Image 3: An apple!

Finally, I added textures to my snake. I wanted to try to draw scales, but I had trouble making them look any good, so I just went with a diamond-back look. I played around with the colors of the scene a bit, and decided I didn't like the boring sphere for food, so I decided to make it red and hierarchically model an apple with a stem.

Image 4: Game over screen

Lastly I had a bit of time left over at the end, and I wanted to have some sort of animation for when the game ended. I worked on doing some boids-style particle affect like we did in class, but I was having a lot of problems rendering a lot of particles on my virtual machine, so I decided just to go with a simple animation with a few spheres. Basically spheres appear and grow and grow until they fill up the screen.

Image 5: A high score