James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

ClassicEngine Class Reference

ClassicEngine Class Reference

ClassicEngine Class. More...

#include <ClassicEngine.h>

Public Member Functions

 ClassicEngine ()
 Create an engine object for the Classic game mode.
 ~ClassicEngine ()
 Delete a Classic Engine object to free up memory.
void init (Ball &ball, Map &map)
 Initialise the engine object with the start position of the game map and fix the ball to the centre of the screen.
void classic_update (Ball &ball, FXOS8700CQ &accelerometer, Map &map)
 Read the accelerometer input and update the map's motion using it.
void classic_draw (N5110 &lcd, Map &map, Ball &ball)
 render the game mode contents on the LCD screen
bool finished ()
 Check if the player has successfully reached the end of the game mode.
void mode_complete (N5110 &lcd, Gamepad &gamepad, int fps)
 Display the end of game mode screen with the player's completion time.
bool mode_failed (N5110 &lcd, Gamepad &gamepad, Ball &ball, Map &map)
 Display game over screen and Check whether player wants to play again returns true - player wants to return to start menu false - player wants to play again.

Detailed Description

ClassicEngine Class.

Library to power the Classic game mode Includes feature to check for and update high scores

Author:
James Cummins
#include "mbed.h"
#include "ClassicEngine.h"

ClassicEngine engine;
Ball ball;
Map map;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL);
Gamepad gamepad;

int main(){
    int fps = 30;               //set the game mode frames per sec
    classic.init(ball, map);    //initialise the engine before use
    bool collision = false;     //create bool to check whether to continue
    while(!(collision)){
        
    //classic update contains methods for reading and updating map and ball
        classic.classic_update(ball, accelerometer, map);
    //use clear, classic draw and refresh together to re-render the screen each frame
        lcd.clear();
        classic.classic_draw(lcd, map, ball);
        lcd.refresh();
        wait(1/fps);
    //Check for successful completion of game and display appropriate message
        if(classic.finished()){         //check if the game has been completed
    //mode_complete includes feature to update high scores
            classic.mode_complete(lcd, gamepad, fps);
            break;
        }
    //Check for game failure and display appropriate message with option to
    //restart or go back
        if(map.check_wall_collision(gamepad, ball)){    //end the game if collision with wall
            collision = classic.mode_failed(lcd, gamepad, ball, map);   //gives the option to restart the game (and stay in while loop) or quit
    //reset the game mode to the beginning if user wants to play again
            if(!(collision)){ classic.init(ball, map); }
        }
    }
}

Definition at line 61 of file ClassicEngine.h.


Constructor & Destructor Documentation

Create an engine object for the Classic game mode.

Definition at line 4 of file ClassicEngine.cpp.

~ClassicEngine (  )

Delete a Classic Engine object to free up memory.

Definition at line 8 of file ClassicEngine.cpp.


Member Function Documentation

void classic_draw ( N5110 lcd,
Map map,
Ball ball 
)

render the game mode contents on the LCD screen

Parameters:
lcd- N5110 object to access screen
map- Map object to draw Map in current position
ball- Ball object to draw ball in fixed position

Definition at line 32 of file ClassicEngine.cpp.

void classic_update ( Ball ball,
FXOS8700CQ &  accelerometer,
Map map 
)

Read the accelerometer input and update the map's motion using it.

Update the absolute position of the ball in relation to the map.

Parameters:
ball- Ball object to access ball's position
accelerometer- FXOS8700CQ object to read user's input motion
map- Map object to update map

Definition at line 22 of file ClassicEngine.cpp.

bool finished (  )

Check if the player has successfully reached the end of the game mode.

Returns:
true - ball has reached finish line false - ball has not reached finish line

Definition at line 37 of file ClassicEngine.cpp.

void init ( Ball ball,
Map map 
)

Initialise the engine object with the start position of the game map and fix the ball to the centre of the screen.

Initialise frames counted to 0.

Parameters:
ball- Ball object to set the ball's position
map- Map object to set the map's initial position

Definition at line 12 of file ClassicEngine.cpp.

void mode_complete ( N5110 lcd,
Gamepad gamepad,
int  fps 
)

Display the end of game mode screen with the player's completion time.

Parameters:
lcd- N5110 object to draw display on LCD screen
gamepad- Gamepad object to check for user pushing button
fps- integer value of game's frames per second

Definition at line 49 of file ClassicEngine.cpp.

bool mode_failed ( N5110 lcd,
Gamepad gamepad,
Ball ball,
Map map 
)

Display game over screen and Check whether player wants to play again returns true - player wants to return to start menu false - player wants to play again.

Definition at line 67 of file ClassicEngine.cpp.