Professional Documents
Culture Documents
User Manual
1.2 Controls
While in game, you can move around with 4 buttons.
Moreover should you need to stop the game, but don’t want to lose your
score you can pause the game pressing S5.
If you wish to restart or start back after a gameover, you have to press
the S1 (RESET) button.
1.3 Levels
We prepared 8 different levels (easy 1 · · · 8 difficult) with different pattern of
walls. The speed of the snake will increase accordingly to the level difficulty
and to how much food was eaten.
1
1.4 Eating food
Food appears randomly in every part of the screen.
If you are enough lucky you might have the chance of eating a special
food; this kind of food will make your snake grow bigger than special food,
but it will slow down its speed. However you have to eat this special food
as soon as possibile since it goes away very quickly.
2
Chapter 2
Reference Manual
In this chapter you will find all the details of the technical implementation
adopted in our game.
3
2.2 Files Scheme
The game code is divided in four main files, each one created for dealing
with the display, the main algorithm and the input output. All the other
files present in our project are standard ARM libraries with the exception
of LCD_Data.c which has been modified to store pictures and number fonts
used in the game.
2.2.1 Main.c
This file contains the core loop of the algorithm which is executed at every
clock cycle. It provides initialization of the LCD, of the reference Matrix
and of the game itself (by selecting the level difficulty).
2.2.2 display.c
This file contains every function involved in writing or reading on the screen,
from the very low level, turning on and off single pixels, to the high level
operations, printing walls and food on the screen.
2.2.3 gamelib.c
This file contains general functions used in the game like level selection and
matrix intialization. It also contains the all-important function Move_Snake()
used for adjusting the snake length and behaviour to adopt at every move.
2.2.4 io.c
This file contains all the other I/O functions not related with the screen,
especially keyboard input and LED and PWM operations.
4
2.4 Algorithm
2.4.1 Initialization
The code begins with printing the title picture and with playing the welcome
tune by calling Print_Pic() and PlayTune() while LEDs turn on and off
following different patterns (LedDisp()). Then it clears the screen and asks
to choose the level difficutly in Select_Level(); this function returns an
integer based on how much time the user took to make the selection and the
program uses this number to initialize the rand() seed.
2.4.4 Directions
Firstly there is a check whether to delete the special food or not. Then
the program calls Move_Snake() which moves the snake in the screen in
the direction selected before and performs the various operations based on
the content of the cell the snake moved into. Finally it polls if a button is
pressed; if it is, it updates the direction of the next move, if not the new
direction is the same as in the previous move.
5
2.4.5 Cell Content Handling
Move_Snake() updates the position of the snake by updating the pointers of
the head and tail and checks the content of the cell the snake just moved in.
If it is EMPTY and the tail must be updated, it does so; if it is FOOD, it clears
all the food positions, doesn’t delete the tail (which will not be updated for 3
moves) and increases the speed and the score; if it is FOODSP it replicates the
operation of the FOOD case with the difference of slowing down the speed,
incrementing the score ten times more than normal and not allowing tail
update for 8 moves; if it is WALL or a direction the program executes the
GameOver() function. In every case the LEDs or the PWM (or both) are
activated.
6
Contents
1 User Manual 1
1.1 Basic Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.4 Eating food . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Your score . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Reference Manual 3
2.1 Board and Tools . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Files Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.1 Main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.2 display.c . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.3 gamelib.c . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.4 io.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Reference Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . 5
2.4.2 Matrix management . . . . . . . . . . . . . . . . . . . 5
2.4.3 Snake Handling . . . . . . . . . . . . . . . . . . . . . . 5
2.4.4 Directions . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4.5 Cell Content Handling . . . . . . . . . . . . . . . . . . 6
2.4.6 Game Over . . . . . . . . . . . . . . . . . . . . . . . . 6