Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Map Class Reference
#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
#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
Member Function Documentation
| void draw | ( | N5110 & | lcd ) |
| 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
| Vector2D get_map_display | ( | ) |
| void init | ( | ) |
| void read_input | ( | FXOS8700CQ & | accelerometer, |
| Ball & | ball | ||
| ) |
| void set_map_display | ( | Vector2D | coord ) |
Generated on Thu Jul 14 2022 00:39:27 by
1.7.2