Dependencies:
N5110
PinDetect
PowerControl
mbed
Fork of
DocTest
by Craig Evans
« Back to documentation index
main.h File Reference
Header file containing functions prototypes, defines and global variables.
More...
Go to the source code of this file.
Namespaces
namespace lcd
connections lcd mosi connections for nokia N5110
namespace myleds
busout to onboard mbed LEDS for debug
namespace leds
bus output for game indicator leds
namespace startButton
for start button ISR
namespace resetButton
in for reset button ISR
namespace startGame
Ticker to set updateGameFlag.
namespace button
Joysitck button GPIO.
namespace xPot
joystick x pot GPIO
namespace yPot
joystick y pot GPIO
namespace serial
Print to terminal for debug.
Functions
vector< int > snakeX (5)
vector< int > snakeY (5, 27)
void displaySplash ()
Displays a Snake Logo Splash Screen.
void calibrateJoystick ()
Reads default positions of the joystick to calibrate later readings.
void updateJoystick ()
Reads X and Y pots and determines what direction joystick is in.
void easySelected ()
Displays easy selected on display and updates gameSpeed variable.
void mediumSelected ()
Displays Medium selected on display and updates gameSpeed variable.
void hardSelected ()
Displays Hard selected on display and updates gameSpeed variable.
void classicModeSelected ()
Displays classicMode selected on display and updates gameMode variable.
void boundaryModeSelected ()
Displays BoundaryMode selected on display and updates gameMode variable.
void checkSelectedGameMode ()
Uses joystick direction to determine what difficulty too update to.
void checkSelectedDifficulty ()
Uses joystick direction to determine what game mode too update to.
void startingSnake ()
resizes the vector back to 5 incase game is reset prints to screen using coordinates stored in the snakeX and snakeY vectors drawRect used for 2x2 snake
void randomiseFood ()
Funtion to generate random food.
void hardBoundary ()
prints a solid boundary around screen for use in BOUNDARY mode
void classicBoundary ()
Prints a dotted boundary around the screen for use in CLASSIC mode.
void updateSnakeVector ()
Uses joystick direction and previous joysitck direction to determine new direction of snake Clears Tail of Snake Elements in SnakeX and Y are shifted along one to the right New snake head cordinates are added to last element of vector depending on direction.
void gameOverTune ()
triggers Buzzer to play when gameover
void gameOver ()
called when game is over.
void checkForCollision ()
called in boundary mode everytime snake updates checks for a collision with boundary
void checkForFood ()
Everytime snake is updated compares coordinates of snake to the food to see if they match.
void startButtonPressed ()
function called when pindetect startButton is triggered
void updateBrightness ()
Reads from brightness potentiometer to update lcd brightness.
void updateGameISR ()
function called by updateGame timer
void printVectorContent ()
For debug.
void pauseButtonPressed ()
function called when interupt occurs on joystick button
void checkForCollisionWithSelf (int i)
Compares all elements in snake vectors against head of snake.
Variables
int score = 5
char buffer [14]
bool gamePaused = 0
int foodX [1]
int foodY [1]
int gameState = 0
float gameSpeed
int updateGameFlag = 0
Detailed Description
Header file containing functions prototypes, defines and global variables.
Game of Snake Revision 1.0.
Author: Michael Birney
Date: April 2015
Definition in file main.h .
Function Documentation
void boundaryModeSelected
(
)
Displays BoundaryMode selected on display and updates gameMode variable.
Definition at line 176 of file main.cpp .
void calibrateJoystick
(
)
Reads default positions of the joystick to calibrate later readings.
Definition at line 46 of file main.cpp .
void checkForCollision
(
)
called in boundary mode everytime snake updates checks for a collision with boundary
Definition at line 534 of file main.cpp .
void checkForCollisionWithSelf
(
int
i )
Compares all elements in snake vectors against head of snake.
Parameters:
i - integer signifying element in snake vector
Definition at line 660 of file main.cpp .
Everytime snake is updated compares coordinates of snake to the food to see if they match.
Definition at line 544 of file main.cpp .
void checkSelectedDifficulty
(
)
Uses joystick direction to determine what game mode too update to.
Definition at line 232 of file main.cpp .
void checkSelectedGameMode
(
)
Uses joystick direction to determine what difficulty too update to.
Definition at line 192 of file main.cpp .
Prints a dotted boundary around the screen for use in CLASSIC mode.
Definition at line 365 of file main.cpp .
void classicModeSelected
(
)
Displays classicMode selected on display and updates gameMode variable.
Definition at line 159 of file main.cpp .
Displays a Snake Logo Splash Screen.
Definition at line 82 of file main.cpp .
Displays easy selected on display and updates gameSpeed variable.
Definition at line 108 of file main.cpp .
called when game is over.
displays final score for user
Definition at line 494 of file main.cpp .
triggers Buzzer to play when gameover
Definition at line 469 of file main.cpp .
prints a solid boundary around screen for use in BOUNDARY mode
Definition at line 345 of file main.cpp .
Displays Hard selected on display and updates gameSpeed variable.
Definition at line 142 of file main.cpp .
Displays Medium selected on display and updates gameSpeed variable.
Definition at line 125 of file main.cpp .
void pauseButtonPressed
(
)
function called when interupt occurs on joystick button
Definition at line 638 of file main.cpp .
void printVectorContent
(
)
For debug.
Prints content of snakeX and snakeY vectors
Definition at line 628 of file main.cpp .
Funtion to generate random food.
Definition at line 317 of file main.cpp .
vector to store all x coordinates of snake
vector<int> snakeY
(
5
,
27
)
vector to store all y coordinates of snake
void startButtonPressed
(
)
resizes the vector back to 5 incase game is reset prints to screen using coordinates stored in the snakeX and snakeY vectors drawRect used for 2x2 snake
Definition at line 293 of file main.cpp .
void updateBrightness
(
)
Reads from brightness potentiometer to update lcd brightness.
Definition at line 616 of file main.cpp .
function called by updateGame timer
Definition at line 623 of file main.cpp .
Reads X and Y pots and determines what direction joystick is in.
Definition at line 53 of file main.cpp .
void updateSnakeVector
(
)
Uses joystick direction and previous joysitck direction to determine new direction of snake Clears Tail of Snake Elements in SnakeX and Y are shifted along one to the right New snake head cordinates are added to last element of vector depending on direction.
Definition at line 387 of file main.cpp .
Variable Documentation
stores data to print to screen
Definition at line 69 of file main.h .
int to store x value of food
Definition at line 102 of file main.h .
int to store y value of food
Definition at line 103 of file main.h .
bool to store paused state
Definition at line 99 of file main.h .
changes depending on difficulty selected
Definition at line 107 of file main.h .
indicator for various game states
Definition at line 104 of file main.h .
integer to store user score
Definition at line 60 of file main.h .
ISR to update game
Definition at line 108 of file main.h .