James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

BrickBreakerEngine Class Reference

BrickBreakerEngine Class Reference

BrickBreakerEngine Class. More...

#include <BrickBreakerEngine.h>

Public Member Functions

 BrickBreakerEngine ()
 Create an engine object for the BrickBreaker game mode.
 ~BrickBreakerEngine ()
 Delete a brickbreaker engine object to free up memory.
void init (int radius, Ball &ball)
 Initialise the engine object Initialises the ball object used and sets the position of the first square to hit with a random number.
void brickbreaker_draw (N5110 &lcd, Ball &ball)
 draw the features of the brickbreaker game mode on the LCD screen
void set_score (int score)
 set the stored score for the brickbreaker mode to a specific value
void check_square_collision (AnalogIn &randnoise, Ball &ball)
 check whether the ball has collided with the square and, if so, randomly generate a new square based on random noise on a disconnected mbed port
void time_warning (Gamepad &gamepad, int frame, int fps)
 Check how long left in the game mode, and display LED sequence to show how long's left.
void write_high_scores ()
 read the current high scores, check if the current score is higher than any and update the list accordingly
void end (Gamepad &gamepad, N5110 &lcd)
 display the end of game screen with the player's final score

Detailed Description

BrickBreakerEngine Class.

Library to power the BrickBreaker game mode Includes feature to check for and write high scores

Author:
James Cummins
#include "mbed.h"
#include "BrickBreakerEngine.h"
#define RADIUS 3

BrickBreakerEngine engine;   //Constructor to create engine object
AnalogIn randnoise(PTB0);    //Get a random noise signal to seed the random square generator
Gamepad gamepad;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Ball ball;
FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL);

int main(){
    //Initialise the engine object with the ball's radius and the ball object
    engine.init(RADIUS, ball)
    int total_frames = 30000;
    for (int i = 0; i < total_frames; i++){
        //Not strictly needed as included in the initialiser
        engine.set_score(0);
        lcd.clear();
        ball.read_input(accelerometer);
        ball.update()
        
        //Check for a collision between a square and the ball object
        engine.check_square_collision(randnoise, ball);     //increments score if there's a collision
        
        engine.draw(lcd, ball);
        lcd.refresh();
        
        time_warning();
    }
    //End screen concludes game mode
    engine.end(gamepad, lcd);
    engine.write_high_scores;   //only needs computing once so perform after while loop
}

Definition at line 59 of file BrickBreakerEngine.h.


Constructor & Destructor Documentation

Create an engine object for the BrickBreaker game mode.

Definition at line 4 of file BrickBreakerEngine.cpp.

Delete a brickbreaker engine object to free up memory.

Definition at line 8 of file BrickBreakerEngine.cpp.


Member Function Documentation

void brickbreaker_draw ( N5110 lcd,
Ball ball 
)

draw the features of the brickbreaker game mode on the LCD screen

Parameters:
lcd- N5110 object to interact with the LCD screen
ball- Ball object to access ball drawing function

Definition at line 22 of file BrickBreakerEngine.cpp.

void check_square_collision ( AnalogIn &  randnoise,
Ball ball 
)

check whether the ball has collided with the square and, if so, randomly generate a new square based on random noise on a disconnected mbed port

Parameters:
randnoise- AnalogIn reading from a disconnected port
ball- Ball object to get the ball's position

Definition at line 38 of file BrickBreakerEngine.cpp.

void end ( Gamepad gamepad,
N5110 lcd 
)

display the end of game screen with the player's final score

Parameters:
gamepad- Gamepad object for use of buttons
lcd- N5110 object to display end message on screen

Definition at line 119 of file BrickBreakerEngine.cpp.

void init ( int  radius,
Ball ball 
)

Initialise the engine object Initialises the ball object used and sets the position of the first square to hit with a random number.

Gets the ball radius from ball object

Parameters:
radius- integer for the ball's radius
ball- object of Ball.h class

Definition at line 12 of file BrickBreakerEngine.cpp.

void set_score ( int  score )

set the stored score for the brickbreaker mode to a specific value

Parameters:
score- integer with desired score value

Definition at line 28 of file BrickBreakerEngine.cpp.

void time_warning ( Gamepad gamepad,
int  frame,
int  fps 
)

Check how long left in the game mode, and display LED sequence to show how long's left.

Parameters:
gamepad- Gamepad object to turn on and off LEDs
frame- integer number of frames that have passed
fps- integer number of frames per second the game runs at

Definition at line 96 of file BrickBreakerEngine.cpp.

void write_high_scores (  )

read the current high scores, check if the current score is higher than any and update the list accordingly

Definition at line 82 of file BrickBreakerEngine.cpp.