Calum Johnston / Mbed 2 deprecated BrickBreaker

Dependencies:   N5110 PinDetect PowerControl mbed

Embed: (wiki syntax)

« Back to documentation index

BrickBreaker.cpp File Reference

BrickBreaker.cpp File Reference

Function implementations. More...

Go to the source code of this file.

Functions

void readHighScores ()
 Read High Scores.
void writeHighScores ()
 Write High Scores.
void newLevel ()
 New Level.
void pause ()
 Pause.
int getNumBricks ()
 Get Number of Bricks.
int lifeLost ()
 Lost Life.
void game (int g)
 Game.
void highScores ()
 High Scores.
void help ()
 Help.
void gameOver ()
 Game Over.
void newScreen ()
 New Screen.
void getMenuSelect ()
 Get Menu Select.
void menu ()
 Menu.
void dispLives ()
 Display Lives.
void dispScore ()
 Displays Score.
void doBricks ()
 Do the Bricks.
void initBricks (int l)
 Initialise the Bricks.
void clearBricks ()
 Clear Bricks.
void getBrickTouch (int x, int y)
 Get Brick Touch.
void calibrateJoystick ()
 Calibrate Joystick.
void updateJoystick ()
 Update Joystick.
void paddle ()
 Paddle.
void getTouchFlag ()
 Get Ball Touch Flag.
int setAngle ()
 Set Ball Angle.
void ball ()
 Ball.
void moveBall1 (int d)
 Move Ball (1)
void moveBall2 (int d)
 Move Ball (2)
void borderInit ()
 Initialise the Borders.

Detailed Description

Function implementations.

Definition in file BrickBreaker.cpp.


Function Documentation

void ball (  )

Ball.

Move the ball

2-step movement for the ball - combines moveBall1() and moveBall2() with setAngle() and doBricks() to ensure game updates properly.

NB: wait() functions were included to slow down the motion of the ball to a reasonable speed. A timer would have been preferable but the game ceased to function if this implementation was used.

Definition at line 932 of file BrickBreaker.cpp.

void borderInit (  )

Initialise the Borders.

Draws the boundaries so that the ball cannot leave the screen through the sides or top. Also draws some graphics for containing the scores and remaining lives.

Definition at line 1112 of file BrickBreaker.cpp.

void calibrateJoystick (  )

Calibrate Joystick.

Initialises the built in button in the joystick in PullUp mode. Also reads the initial values of the joystick for reference.

Definition at line 465 of file BrickBreaker.cpp.

void clearBricks (  )

Clear Bricks.

Loops through all bricks and clears any that are set to be cleared

Definition at line 423 of file BrickBreaker.cpp.

void dispLives (  )

Display Lives.

Displays the current number of remaining lives on the screen

Definition at line 345 of file BrickBreaker.cpp.

void dispScore (  )

Displays Score.

Displays the current score on the screen. The score is displayed vertical but the score is often multiple digits so modulus was used to split up the digits.

Definition at line 351 of file BrickBreaker.cpp.

void doBricks (  )

Do the Bricks.

Does getBrickTouch() on all bricks, draws any that are set to be drawn and clears any that are set to be cleared

Definition at line 370 of file BrickBreaker.cpp.

void game ( int  g )

Game.

Pulls together various other functions to run the game

Parameters:
g- If true, game runs. If false, game stops. Used to pause the game

Definition at line 134 of file BrickBreaker.cpp.

void gameOver (  )

Game Over.

Displays the dreaded Game Over screen. If the score is greater than any of the high scores they will be updated accordingly and the player informed.

Definition at line 212 of file BrickBreaker.cpp.

void getBrickTouch ( int  x,
int  y 
)

Get Brick Touch.

Checks to see if any of the pixels surrounding a given brick are set - i.e. if something is touching one

Parameters:
x- the horizontal index of the brick check
y- the vertical index of the brick to check

Definition at line 438 of file BrickBreaker.cpp.

void getMenuSelect (  )

Get Menu Select.

Checks the joystick direction and assigns the cursor a new position based on that

Definition at line 285 of file BrickBreaker.cpp.

int getNumBricks (  )

Get Number of Bricks.

Returns:
- Number of remaining bricks

Finds the number of bricks remaining on the screen

Definition at line 109 of file BrickBreaker.cpp.

void getTouchFlag (  )

Get Ball Touch Flag.

Check to see if the ball is touching anything

Definition at line 537 of file BrickBreaker.cpp.

void help (  )

Help.

Displays the various pages of help available, moves the cursor to the current position

Definition at line 162 of file BrickBreaker.cpp.

void highScores (  )

High Scores.

Pulls the high score data from the internal memory and displays them on the screen

Definition at line 146 of file BrickBreaker.cpp.

void initBricks ( int  l )

Initialise the Bricks.

Populate the array storing the state of the bricks for drawing

Parameters:
l- The game level to be initialised. Predefined when l<2 and random afterwards.

Definition at line 390 of file BrickBreaker.cpp.

int lifeLost (  )

Lost Life.

Returns:
1 - If a life is lost. I think this was for debugging CHECK THIS LATER

Definition at line 120 of file BrickBreaker.cpp.

void menu (  )

Menu.

Displays the menu screen and moves the cursor to the current position

Definition at line 328 of file BrickBreaker.cpp.

void moveBall1 ( int  d )

Move Ball (1)

First iteration of ball motion

Parameters:
d- The direction to move the ball in - quantised into 16 separate directions

Definition at line 951 of file BrickBreaker.cpp.

void moveBall2 ( int  d )

Move Ball (2)

Second iteration of ball motion

Parameters:
d- The direction to move the ball in - quantised into 16 separate directions

Definition at line 1035 of file BrickBreaker.cpp.

void newLevel (  )

New Level.

Updates the level and redraws the bricks

Called when getNumBricks() returns 0

Definition at line 88 of file BrickBreaker.cpp.

void newScreen (  )

New Screen.

Called on a click of the joystick from the menu, changes the information displayed on the screen. Depends on the position of the cursor

Definition at line 243 of file BrickBreaker.cpp.

void paddle (  )

Paddle.

Move the paddle left and right

Checks the position of the joystick and updates the postion of the paddle based on that.

NB: The entire row is cleared when in theory only the prior position should need to be. In practise this does not work and the row does not properly cleared.

Definition at line 515 of file BrickBreaker.cpp.

void pause (  )

Pause.

Reverses the value of StartStop to Pause/Unpause the game

Definition at line 102 of file BrickBreaker.cpp.

void readHighScores (  )

Read High Scores.

Reads the current values of the high scores from the internal memory

Definition at line 72 of file BrickBreaker.cpp.

int setAngle (  )

Set Ball Angle.

Returns:
d The direction that the ball is to move in

Set the new direction of the ball based on what the edges of the ball are touching and the current angle of the ball

Definition at line 579 of file BrickBreaker.cpp.

void updateJoystick (  )

Update Joystick.

Checks the x and y values of the potentiometers and assigns the joystick a direction based on that.

Definition at line 474 of file BrickBreaker.cpp.

void writeHighScores (  )

Write High Scores.

Writes the updated values of the high scores to the internal memory

Definition at line 80 of file BrickBreaker.cpp.