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.h
00001 #ifndef MAP_H 00002 #define MAP_H 00003 00004 // Included Headers ------------------------------------------------------------ 00005 #include "mbed.h" 00006 #include "N5110.h" 00007 #include "Position.h" 00008 00009 /** Map class 00010 * @brief Draws 00011 * @author Benjamin Evans, University of Leeds 00012 * @date April 2020 00013 */ 00014 class Map: private Position{ 00015 public: 00016 /** Constructor */ 00017 Map(); 00018 00019 /** Destructor */ 00020 ~Map(); 00021 00022 /** Initialises Spaceship 00023 * @param pad @details : Gamepad object 00024 */ 00025 void init(Gamepad &pad); 00026 00027 /** Draws map out of combination of random triangle hight and random 00028 * length lines so map is different each new game and loops round at ends 00029 * @param lcd @details N5110 object and 00030 * @param d_ @details Direction variable for move map 00031 */ 00032 void draw_map(N5110 &lcd, Direction d_); 00033 00034 // Accessors and mutators -------------------------------------------------- 00035 00036 /** Gets x postion of the map for testing 00037 * @return maps x postion 00038 */ 00039 int get_position_x_map(); 00040 00041 /** Gets map length 00042 * @return map_length_ 00043 */ 00044 int get_length_map(); 00045 00046 private: 00047 // Functions prototypes ---------------------------------------------------- 00048 00049 /** Draws a triangle from position with specified hight wich represents 00050 * a mountain of the map 00051 * @param lcd @details N5110 object 00052 * @param triangle_height @details random hight of triangle produced 00053 */ 00054 void draw_triangle(N5110 &lcd, int triangle_height); 00055 00056 /** Draws a horizontal line with specified length to represent flat land 00057 * on map 00058 * @param lcd @details N5110 object 00059 * @param line_length @details length of horozontal line 00060 */ 00061 void draw_line(N5110 &lcd, int line_length); 00062 00063 /** Duplicates the first part of the map to fill the gap when the map 00064 * loops round forwards 00065 * @ param lcd @details N5110 object 00066 */ 00067 void check_duplicates_map_forward(N5110 &lcd); 00068 00069 /** Duplicates the last part of the map to fill the gap when the map 00070 * loops round backwards 00071 * @ param lcd @details N5110 object 00072 */ 00073 void check_duplicates_map_backwards(N5110 &lcd); 00074 00075 /** Fills random lengths and hights arrays and fills arrays with random 00076 * integers so same random map is drawn each frame 00077 * @param Pad @details : Gampad adc object used to generate seed 00078 */ 00079 void fill_random_arrays(Gamepad &pad); 00080 00081 /** Calulates the map movement depeding on spaceship positions and 00082 * joystick input 00083 * @param d_ @details Direction object of joystick 00084 * @retrun inger @details Move map value for map draw function 00085 */ 00086 int calc_map_movement(Direction d_); 00087 00088 // Variables --------------------------------------------------------------- 00089 00090 /** Store random heights triangles */ 00091 int rand_heights_[12]; 00092 00093 /** Store lengths of lines */ 00094 int rand_lengths_[12]; 00095 00096 /** Store the final element used in the random array befor the break 00097 * in draw map 00098 */ 00099 int final_random_element_used_; 00100 00101 /** Required to reset the map to it's origonal postion at end of each 00102 * frame, as draw line and triangle functions change position_x_map_ 00103 */ 00104 int reset_position_x_map_to_origonal_; 00105 00106 /** Length of map */ 00107 int map_length_; 00108 }; 00109 00110 #endif
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2