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/Map.h@15:90b6821bcf64, 2020-04-28 (annotated)
- Committer:
- evanso
- Date:
- Tue Apr 28 19:13:12 2020 +0000
- Revision:
- 15:90b6821bcf64
- Parent:
- 14:7419c680656f
- Child:
- 18:11068b98e261
Added DEBUG compile macros to check calculate_map_map was producing correct output
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| evanso | 6:12e8433382b3 | 1 | #ifndef MAP_H |
| evanso | 6:12e8433382b3 | 2 | #define MAP_H |
| evanso | 6:12e8433382b3 | 3 | |
| evanso | 15:90b6821bcf64 | 4 | // Included libraries ----------------------------------------------------------- |
| evanso | 6:12e8433382b3 | 5 | #include "mbed.h" |
| evanso | 6:12e8433382b3 | 6 | #include "N5110.h" |
| evanso | 13:12276eed13ac | 7 | #include "Gamepad.h" |
| evanso | 11:ab578a151f67 | 8 | |
| evanso | 6:12e8433382b3 | 9 | /** Map class |
| evanso | 8:dd1037c5435b | 10 | @brief Draws |
| evanso | 6:12e8433382b3 | 11 | @author Benjamin Evans, University of Leeds |
| evanso | 6:12e8433382b3 | 12 | @date April 2020 |
| evanso | 6:12e8433382b3 | 13 | */ |
| evanso | 6:12e8433382b3 | 14 | |
| evanso | 6:12e8433382b3 | 15 | class Map { |
| evanso | 6:12e8433382b3 | 16 | public: |
| evanso | 6:12e8433382b3 | 17 | /** Constructor */ |
| evanso | 6:12e8433382b3 | 18 | Map(); |
| evanso | 6:12e8433382b3 | 19 | |
| evanso | 6:12e8433382b3 | 20 | /** Destructor */ |
| evanso | 6:12e8433382b3 | 21 | ~Map(); |
| evanso | 6:12e8433382b3 | 22 | |
| evanso | 14:7419c680656f | 23 | /** Initalises Spaceship |
| evanso | 15:90b6821bcf64 | 24 | * @param pad @details : Gampad object |
| evanso | 14:7419c680656f | 25 | */ |
| evanso | 13:12276eed13ac | 26 | void init(Gamepad &pad); |
| evanso | 11:ab578a151f67 | 27 | |
| evanso | 14:7419c680656f | 28 | /** Draws map out of combination of random hight traingle and random |
| evanso | 14:7419c680656f | 29 | * length lines so map is differnt each new game and loops roudn at ends |
| evanso | 15:90b6821bcf64 | 30 | * @param lcd, move_map @details : N5110 object and variable to move x postion of map |
| evanso | 11:ab578a151f67 | 31 | */ |
| evanso | 11:ab578a151f67 | 32 | void draw_map(N5110 &lcd, int move_map); |
| evanso | 14:7419c680656f | 33 | |
| evanso | 14:7419c680656f | 34 | /** Gets 11 random integers for random lengths and hights arrays |
| evanso | 14:7419c680656f | 35 | * and fills arrays with the random integers so same random map is drawn each frame |
| evanso | 15:90b6821bcf64 | 36 | * @param Pad @details : Gampad adc object used to generate seed |
| evanso | 14:7419c680656f | 37 | */ |
| evanso | 14:7419c680656f | 38 | void fill_random_arrays(Gamepad &pad); |
| evanso | 11:ab578a151f67 | 39 | |
| evanso | 13:12276eed13ac | 40 | // Accessors and mutators ---------------------------------------------- |
| evanso | 6:12e8433382b3 | 41 | |
| evanso | 11:ab578a151f67 | 42 | /** Gets x postion of the map |
| evanso | 11:ab578a151f67 | 43 | * @return maps x postion |
| evanso | 11:ab578a151f67 | 44 | */ |
| evanso | 11:ab578a151f67 | 45 | int get_position_x_map(); |
| evanso | 11:ab578a151f67 | 46 | |
| evanso | 11:ab578a151f67 | 47 | private: |
| evanso | 13:12276eed13ac | 48 | // Functions prototypes ------------------------------------------------ |
| evanso | 11:ab578a151f67 | 49 | |
| evanso | 7:0af4ced868f5 | 50 | /** Draws a triangle from position with specified hight wich represents a mountain of the map |
| evanso | 15:90b6821bcf64 | 51 | * @param lcd, tirangle_height @details : N5110 object and teh random hight of triangle produced |
| evanso | 7:0af4ced868f5 | 52 | */ |
| evanso | 14:7419c680656f | 53 | void draw_triangle(N5110 &lcd, int triangle_height); |
| evanso | 7:0af4ced868f5 | 54 | |
| evanso | 7:0af4ced868f5 | 55 | /** Draws a horizontal line with specified length to represent flat land on map |
| evanso | 15:90b6821bcf64 | 56 | * @param lcd, tirangle_height @details : N5110 object and random length of line produced |
| evanso | 7:0af4ced868f5 | 57 | */ |
| evanso | 7:0af4ced868f5 | 58 | void draw_line(N5110 &lcd, int line_length); |
| evanso | 7:0af4ced868f5 | 59 | |
| evanso | 11:ab578a151f67 | 60 | /** Duplicates the first part of the map to fill the gap when the map loops round |
| evanso | 15:90b6821bcf64 | 61 | * @ param lcd @details : N5110 object |
| evanso | 8:dd1037c5435b | 62 | */ |
| evanso | 11:ab578a151f67 | 63 | void check_duplicates_map_forward(N5110 &lcd); |
| evanso | 11:ab578a151f67 | 64 | |
| evanso | 11:ab578a151f67 | 65 | /** Duplicates the last part of the map to fill the gap when the map loops round |
| evanso | 15:90b6821bcf64 | 66 | * @ param lcd @details : N5110 object |
| evanso | 9:1ddb8dc93e48 | 67 | */ |
| evanso | 11:ab578a151f67 | 68 | void check_duplicates_map_backwards(N5110 &lcd); |
| evanso | 11:ab578a151f67 | 69 | |
| evanso | 13:12276eed13ac | 70 | // Variables ----------------------------------------------------------- |
| evanso | 12:1c0b6796aaca | 71 | |
| evanso | 12:1c0b6796aaca | 72 | // Map x postion on lcd |
| evanso | 11:ab578a151f67 | 73 | int position_x_map_; |
| evanso | 7:0af4ced868f5 | 74 | |
| evanso | 12:1c0b6796aaca | 75 | // Map y postion on lcd |
| evanso | 11:ab578a151f67 | 76 | int position_y_map_; |
| evanso | 9:1ddb8dc93e48 | 77 | |
| evanso | 12:1c0b6796aaca | 78 | // Float to store random seed for random function |
| evanso | 11:ab578a151f67 | 79 | float rand_seed_; |
| evanso | 9:1ddb8dc93e48 | 80 | |
| evanso | 12:1c0b6796aaca | 81 | // Map length |
| evanso | 11:ab578a151f67 | 82 | int map_length_; |
| evanso | 11:ab578a151f67 | 83 | |
| evanso | 11:ab578a151f67 | 84 | // Arrays to hold random heights of triangles and lengths of lines |
| evanso | 11:ab578a151f67 | 85 | int rand_heights_[12]; |
| evanso | 7:0af4ced868f5 | 86 | int rand_lengths_[12]; |
| evanso | 11:ab578a151f67 | 87 | |
| evanso | 11:ab578a151f67 | 88 | // To store the final element used in the random array befor the break in draw map |
| evanso | 11:ab578a151f67 | 89 | int final_random_element_used_; |
| evanso | 11:ab578a151f67 | 90 | |
| evanso | 11:ab578a151f67 | 91 | //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_ |
| evanso | 13:12276eed13ac | 92 | int reset_position_x_map_to_origonal_; |
| evanso | 6:12e8433382b3 | 93 | }; |
| evanso | 6:12e8433382b3 | 94 | |
| evanso | 6:12e8433382b3 | 95 | #endif |