jordan harper / Mbed 2 deprecated GameProject

Dependencies:   N5110 mbed

Embed: (wiki syntax)

« Back to documentation index

main.cpp File Reference

main.cpp File Reference

Game Algorithm implementation. More...

Go to the source code of this file.

Functions

void calibrateJoystick ()
 reads default positions of the joystick to calibrate later readings.
void updateJoystick ()
 reads current joystick values relative to the calibrated centre value and calculates direction of joystick.
void clearCells ()
 Turns all cells on the display off.
void flagForWall ()
 flag function for moving wall to call later
void flagForWall2 ()
 flag function for moving wall to call later
void flagForWall3 ()
 flag function for moving wall to call later
void buttonFlag ()
 flag function for joystick button
void menu ()
 displays menu of options that can be selected with joystick
void playGame ()
 initiates game and detects collisions with walls
void BandVMenu ()
 menu for brightness of LCD and volume of buzzer
void brightness ()
 sets brightness of LCD
void volume ()
 sets volume of buzzer
void writeDataToFile ()
 writes data to on board Flash memory.
void readDataFromFile ()
 reads data from the on board Flash memory.
void tone ()
 plays song using different frequencies of PWM through buzzer used to play gameplay music
void deadTone ()
 plays song using different frequencies of PWM through buzzer used to play a 'game over' tone
void scoreCheck ()
 checks current score against the highscore and decides whether to record it or not.
void flagForFlash ()
 flag function for when the game is over
void GameOverFlash ()
 displays "Game Over!" for 3 seconds uses a timer instead of wait() function to save power
void powerSave ()
 Puts mbed into sleep mode and powers down the LCD if the game is left for more than 20 seconds.
void boundries ()
 rules to prevent player object going off the screen
void playerMovement ()
 moves player object on LCD screen to new position.
void fallingWalls ()
 sets different wall objects that move across the screen.
void instructions ()
 gives instructions on how to navigate in menu

Detailed Description

Game Algorithm implementation.

Definition in file main.cpp.


Function Documentation

void BandVMenu (  )

menu for brightness of LCD and volume of buzzer

Parameters:
t- value of specific case
case0 - brightness option
case1 - volume option
case2 - instructions option

Definition at line 408 of file main.cpp.

void boundries (  )

rules to prevent player object going off the screen

Definition at line 752 of file main.cpp.

void brightness (  )

sets brightness of LCD

Parameters:
bright- value of specific case
case0 - sets LCD backlight to 60%
case1 - sets LCD backlight to 80%
case2 - sets LCD backlight to 90%
case3 - sets LCD backlight to 100%
case-1 - sets LCD backlight to 40%
case-2 - sets LCD backlight to 20%
case-3 - turns LCD backlight off

Definition at line 460 of file main.cpp.

void buttonFlag (  )

flag function for joystick button

Definition at line 93 of file main.cpp.

void calibrateJoystick (  )

reads default positions of the joystick to calibrate later readings.

Parameters:
joystick.x0- float value in X-axis to read
joystick.y0- float value in Y-axis to read
Returns:
a definition for the centre value of joystick

Definition at line 24 of file main.cpp.

void clearCells (  )

Turns all cells on the display off.

Parameters:
i- all cells in x direction on screen
j- all cells in y direction on screen
Returns:
a blank screen

Definition at line 65 of file main.cpp.

void deadTone (  )

plays song using different frequencies of PWM through buzzer used to play a 'game over' tone

Parameters:
l- variable to represent each frequency in the array

Definition at line 672 of file main.cpp.

void fallingWalls (  )

sets different wall objects that move across the screen.

each wall has one gap in it which the player must move through to survive. as the score increases, more walls are added to the screen making it more difficult to survive.

Definition at line 811 of file main.cpp.

void flagForFlash (  )

flag function for when the game is over

Definition at line 703 of file main.cpp.

void flagForWall (  )

flag function for moving wall to call later

Definition at line 76 of file main.cpp.

void flagForWall2 (  )

flag function for moving wall to call later

Definition at line 82 of file main.cpp.

void flagForWall3 (  )

flag function for moving wall to call later

Definition at line 88 of file main.cpp.

void GameOverFlash (  )

displays "Game Over!" for 3 seconds uses a timer instead of wait() function to save power

Definition at line 709 of file main.cpp.

void instructions (  )

gives instructions on how to navigate in menu

Definition at line 879 of file main.cpp.

void menu (  )

displays menu of options that can be selected with joystick

Parameters:
case0 - displays the "Play Game" option
case1 - displays the "Settings" option
case2 - displays the "Highscore" option
Returns:
a menu of options that can be selected to initiate other functions

Definition at line 98 of file main.cpp.

void playerMovement (  )

moves player object on LCD screen to new position.

if joystick direction is a diagonal the player object moves one space in y direction and one space in x direction. i.e. upRight direction would cause the player object to move up first, then to the right.

Definition at line 769 of file main.cpp.

void playGame (  )

initiates game and detects collisions with walls

Parameters:
i- x coordinate of player object
j- y coordinate of player object
m- value of specific case
case0 - displays YES option
case1 - displays restart question
case2 - displays NO option

Definition at line 166 of file main.cpp.

void powerSave (  )

Puts mbed into sleep mode and powers down the LCD if the game is left for more than 20 seconds.

this saves power. it can be turned back on again by pushing the joystick button.

Definition at line 725 of file main.cpp.

void readDataFromFile (  )

reads data from the on board Flash memory.

Definition at line 638 of file main.cpp.

void scoreCheck (  )

checks current score against the highscore and decides whether to record it or not.

this is done by scanning the text file saved to the on board Flash memory and then comparing it to the score that has been achieved after the current game is over.

Definition at line 689 of file main.cpp.

void tone (  )

plays song using different frequencies of PWM through buzzer used to play gameplay music

Parameters:
u- variable to represent each frequency in the array

Definition at line 656 of file main.cpp.

void updateJoystick (  )

reads current joystick values relative to the calibrated centre value and calculates direction of joystick.

Parameters:
joystick.x- new float value in X-axis to read
joystick.y- new float value in Y-axis to read
joystick.button- state of joystick button to read
joystick.direction- calculated direction state of joystick
Returns:
direction of joystick

Definition at line 31 of file main.cpp.

void volume (  )

sets volume of buzzer

Parameters:
vol- value of specific case
case0 - sets PWM duty ratio to buzzer to 0.6
case1 - sets PWM duty ratio to buzzer to 0.8
case2 - sets PWM duty ratio to buzzer to 0.9
case3 - sets PWM duty ratio to buzzer to 1.0
case-1 - sets PWM duty ratio to buzzer to 0.4
case-2 - sets PWM duty ratio to buzzer to 0.2
case-3 - sets PWM duty ratio to buzzer to zero (MUTE)

Definition at line 545 of file main.cpp.

void writeDataToFile (  )

writes data to on board Flash memory.

data such as the score and date (if it is better than the previous highscore) is printed to a text file.

Definition at line 625 of file main.cpp.