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.
Diff: Map/Map.h
- Revision:
- 11:ab578a151f67
- Parent:
- 9:1ddb8dc93e48
- Child:
- 12:1c0b6796aaca
diff -r aca793aa7abc -r ab578a151f67 Map/Map.h
--- a/Map/Map.h Wed Apr 22 20:02:22 2020 +0000
+++ b/Map/Map.h Thu Apr 23 18:17:28 2020 +0000
@@ -1,11 +1,12 @@
#ifndef MAP_H
#define MAP_H
-// Include libraries
+/////////////// Include libraries ///////////////
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
+
/** Map class
@brief Draws
@author Benjamin Evans, University of Leeds
@@ -21,8 +22,29 @@
~Map();
/** Initalises Spaceship */
- void init(AnalogIn &adc);
+ void init(AnalogIn &adc);
+
+ /** Draws map out of combination of random hight traingle and random length lines so map is differnt each new game and loops roudn at ends
+ * @param LCD object, move_map variable
+ */
+ void draw_map(N5110 &lcd, int move_map);
+
+ /////////////// accessors and mutators ///////////////
+ /** Gets x postion of the map
+ * @return maps x postion
+ */
+ int get_position_x_map();
+
+ private:
+ /////////////// Functions ///////////////
+
+ /** Gets 11 random integers for random lengths and hights arrays
+ * and stores in array so same random ma is drawn each frame
+ * @param RandGen object
+ */
+ void get_random_arrays(AnalogIn &adc);
+
/** Draws a triangle from position with specified hight wich represents a mountain of the map
* @param LCD object, Hight of trangle
*/
@@ -33,49 +55,34 @@
*/
void draw_line(N5110 &lcd, int line_length);
- /** Gets 12 random integers between 5 and 12 for the random heights of triangles
- * and stores in an array so same random map is drawn when screen refreshesh
- * @param ADC signal input object
- * @return random hieght of the traingle
- */
- void get_random_height_array(AnalogIn &adc);
-
- /** Gets 12 random integers between 15 and 30 for the random lengths of lines
- * and stores in an array so same random map is drawn when screen refreshesh
- * @return random length of lines
- * @param ADC signal input object
+ /** Duplicates the first part of the map to fill the gap when the map loops round
+ * @ param LCD object
*/
- void get_random_length_array(AnalogIn &adc);
-
- /** Draws map out of combination of random hight traingle and random length lines so map is differnt each new game and loops roudn at ends
- * @param LCD object, move_map variable
- */
- void draw_map(N5110 &lcd, int move_map);
-
- /** Gets x postion of the map
- * @return maps x postion
+ void check_duplicates_map_forward(N5110 &lcd);
+
+ /** Duplicates the last part of the map to fill the gap when the map loops round
+ * @ param LCD object
*/
- int get_position_x_map();
+ void check_duplicates_map_backwards(N5110 &lcd);
+
+ /////////////// Variables ///////////////
+
+ int position_x_map_;
- /** Duplicates the first part of the map to fill the gap when the map loops round
- * @ param LCD object, move_map variable
- */
- void check_duplicates_map_forward(N5110 &lcd, int move_map);
+ int position_y_map_;
+ float rand_seed_;
- /** Duplicates the last part of the map to fill the gap when the map loops round
- * @ param LCD object, move_map variable
- */
- void check_duplicates_map_backwards(N5110 &lcd, int move_map);
-
- private:
- int position_x_map_;
- int position_y_map_;
- float rand_seed_;
- int rand_heights_[12];
+ int map_length_;
+
+ // Arrays to hold random heights of triangles and lengths of lines
+ int rand_heights_[12];
int rand_lengths_[12];
- int map_length_;
- int final_random_element_used_;
+
+ // To store the final element used in the random array befor the break in draw map
+ int final_random_element_used_;
+
+ //Required to reset the map to it's origonal postion at end of each frame, as draw line and triangle functions change position_x_map_
int reset_position_x_map_to_origonal_;
};