Assignment9 Writeup
Assignment9 Writeup
This assignment deals with using our knowledge of graphics and all the tricks we have learnt till now to
make an interactive game. I chose to make a simple snake game for this class. Eventually more features
will be added to the game
1. Game ControlsThe arrow keys to set the direction of the game.
W,A,S,D is used to move the camera.
Q,E is used to zoom the camera in and out.
2. Below is the screenshot of the game when it is initially loaded
The blue sphere here represents the head of the snake, and the red spheres represent its body.
The snake is moving towards the right hence it has advanced over to the right of the screen.
3. The user can set the direction for the snake to (up,left,right or down). However the snake cant
go in the reverse direction of what its current direction. i.e If the snake is going right it cant go
left onto itself and vice versa. Below is the screenshot of the game where the direction supplied
by the user is down and hence the snake starts to move down. Also once the head moves
down the body segments shift over to the heads position and hence simulate a train like motion.
6. Structuring of the codeI made the snake as a separate class. I basically made the Snake.h and Snake.cpp files. Below is
the structure of the Snake.h file and how it is structured.
Both the Snake.h and Snake.cpp files are included as part of the existing MyGame project.
A snake object is constructed in MyGame.cpp. It is deleted in cleanup and the draw function of
the snake is called in the method RunGame of MyGame.cpp. This is so because we want to draw
the snake every frame after calculating its updated position.
MyGame also has a method which detects which arrow key is pressed, once it detects this, it
passes the corresponding direction to the snake object.