James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Map Class Reference

Map Class Reference

Map Class. More...

#include <Map.h>

Public Member Functions

 Map ()
 Create a Map object.
 ~Map ()
 Delete a Map object to free up memory.
void init ()
 Set the initial section of the map to be displayed.
void read_input (FXOS8700CQ &accelerometer, Ball &ball)
 Read the accelerometer input and convert it to a rate to move across the map.
void update ()
 Update the map region to be displayed.
void draw (N5110 &lcd)
 Draw the map features on the LCD screen.
Vector2D get_map_display ()
 Get the coordinates of the upper-left most pixel currently being displayed.
void set_map_display (Vector2D coord)
 Set the coordinates for the upper-left most pixel to be displayed on the screen.
bool check_wall_collision (Gamepad &gamepad, Ball &ball)
 Check if the ball has overlapped with a coordinate assigned '1' in the game map.
int get_coordinate (Vector2D coord)
 Get whether a coordinate in the game map is assigned a '1' or a '0'.

Detailed Description

Map Class.

Library for interacting with the Classic game mode Map

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

//Create a map object
Map map;
Ball ball;
Gamepad gamepad;
FXOS8700CQ accelerometer(I2C_SDA, I2C_SCL);
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);

int main(){
    //Initialise the map first
    map.init();
    
    //Use check wall collision to decide whether to continue game or not
    while(!(map.check_wall_collision())){
        
    //read input and update methods check the user input and update
    //the map region to be displayed accordingly
        map.read_input(accelerometer, ball);
        map.update();
        
    //get and set map display can be used to check the intended region of the
    //map to print and correct it if it's out of bounds
        Vector2D map_region = map.get_map_display();
        if(map_region.x > 500){
            map_region.x = 500;
            map.set_map_display(map_region);
        }
        
    //combine clear, draw and refresh to update LCD screen each frame
        lcd.clear();
        map.draw(lcd);
        lcd.refresh();
        
    //Use get coordinate to check if an object (e.g. ball) is centred 
    //on a shaded part of the game map
        Vector2D coord = ball.get_position();
        int pixel = map.get_coordinate(coord);
        if(pixel == 1){ break; }
    }
}

Definition at line 64 of file Map.h.


Constructor & Destructor Documentation

Map (  )

Create a Map object.

Definition at line 3 of file Map.cpp.

~Map (  )

Delete a Map object to free up memory.

Definition at line 6 of file Map.cpp.


Member Function Documentation

bool check_wall_collision ( Gamepad gamepad,
Ball ball 
)

Check if the ball has overlapped with a coordinate assigned '1' in the game map.

Parameters:
gamepad- Gamepad object to access Vector2D struct
ball- Ball object to find the range of coordinates covered by the ball
Returns:
true - wall collision has occurred false - wall collision has not occurred

Definition at line 50 of file Map.cpp.

void draw ( N5110 lcd )

Draw the map features on the LCD screen.

Parameters:
lcd- N5110 object to interact with LCD

Definition at line 30 of file Map.cpp.

int get_coordinate ( Vector2D  coord )

Get whether a coordinate in the game map is assigned a '1' or a '0'.

Parameters:
coord- 2D vector of the x and y coordinates of the desired point
Returns:
1 - coordinate contains a '1' 0 - coordinate contains a '0'

Method included for testing purposes rather than use in game code

Definition at line 76 of file Map.cpp.

Vector2D get_map_display (  )

Get the coordinates of the upper-left most pixel currently being displayed.

Returns:
2D vector of the x and y coordinates

Definition at line 41 of file Map.cpp.

void init (  )

Set the initial section of the map to be displayed.

Definition at line 9 of file Map.cpp.

void read_input ( FXOS8700CQ &  accelerometer,
Ball ball 
)

Read the accelerometer input and convert it to a rate to move across the map.

Parameters:
accelerometer- FXOS8700CQ object to read the player's input motion
ball- Ball object to get the sensitivity to input motion

Definition at line 14 of file Map.cpp.

void set_map_display ( Vector2D  coord )

Set the coordinates for the upper-left most pixel to be displayed on the screen.

Parameters:
a2D vector of the desired coordinates

Definition at line 46 of file Map.cpp.

void update (  )

Update the map region to be displayed.

Definition at line 21 of file Map.cpp.