Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Wed May 27 00:32:04 2020 +0000
Revision:
86:eecd168c3a23
Parent:
85:87bc28b151d8
Fixed bugs in play game and removed any excess included headers.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 6:12e8433382b3 1 #ifndef MAP_H
evanso 6:12e8433382b3 2 #define MAP_H
evanso 6:12e8433382b3 3
evanso 82:3211b31e9421 4 // Included Headers ------------------------------------------------------------
evanso 6:12e8433382b3 5 #include "mbed.h"
evanso 6:12e8433382b3 6 #include "N5110.h"
evanso 27:8bb2bd97c319 7 #include "Position.h"
evanso 11:ab578a151f67 8
evanso 6:12e8433382b3 9 /** Map class
evanso 27:8bb2bd97c319 10 * @brief Draws
evanso 27:8bb2bd97c319 11 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 12 * @date April 2020
evanso 27:8bb2bd97c319 13 */
evanso 27:8bb2bd97c319 14 class Map: private Position{
evanso 6:12e8433382b3 15 public:
evanso 6:12e8433382b3 16 /** Constructor */
evanso 6:12e8433382b3 17 Map();
evanso 6:12e8433382b3 18
evanso 6:12e8433382b3 19 /** Destructor */
evanso 6:12e8433382b3 20 ~Map();
evanso 6:12e8433382b3 21
evanso 85:87bc28b151d8 22 /** Initialises Spaceship
evanso 85:87bc28b151d8 23 * @param pad @details : Gamepad object
evanso 18:11068b98e261 24 */
evanso 13:12276eed13ac 25 void init(Gamepad &pad);
evanso 11:ab578a151f67 26
evanso 85:87bc28b151d8 27 /** Draws map out of combination of random triangle hight and random
evanso 85:87bc28b151d8 28 * length lines so map is different each new game and loops round at ends
evanso 27:8bb2bd97c319 29 * @param lcd @details N5110 object and
evanso 27:8bb2bd97c319 30 * @param d_ @details Direction variable for move map
evanso 18:11068b98e261 31 */
evanso 18:11068b98e261 32 void draw_map(N5110 &lcd, Direction d_);
evanso 11:ab578a151f67 33
evanso 27:8bb2bd97c319 34 // Accessors and mutators --------------------------------------------------
evanso 6:12e8433382b3 35
evanso 18:11068b98e261 36 /** Gets x postion of the map for testing
evanso 18:11068b98e261 37 * @return maps x postion
evanso 18:11068b98e261 38 */
evanso 24:479da6ca0e7e 39 int get_position_x_map();
evanso 24:479da6ca0e7e 40
evanso 27:8bb2bd97c319 41 /** Gets map length
evanso 27:8bb2bd97c319 42 * @return map_length_
evanso 27:8bb2bd97c319 43 */
evanso 24:479da6ca0e7e 44 int get_length_map();
evanso 11:ab578a151f67 45
evanso 11:ab578a151f67 46 private:
evanso 27:8bb2bd97c319 47 // Functions prototypes ----------------------------------------------------
evanso 11:ab578a151f67 48
evanso 27:8bb2bd97c319 49 /** Draws a triangle from position with specified hight wich represents
evanso 27:8bb2bd97c319 50 * a mountain of the map
evanso 27:8bb2bd97c319 51 * @param lcd @details N5110 object
evanso 27:8bb2bd97c319 52 * @param triangle_height @details random hight of triangle produced
evanso 7:0af4ced868f5 53 */
evanso 14:7419c680656f 54 void draw_triangle(N5110 &lcd, int triangle_height);
evanso 7:0af4ced868f5 55
evanso 27:8bb2bd97c319 56 /** Draws a horizontal line with specified length to represent flat land
evanso 27:8bb2bd97c319 57 * on map
evanso 27:8bb2bd97c319 58 * @param lcd @details N5110 object
evanso 27:8bb2bd97c319 59 * @param line_length @details length of horozontal line
evanso 7:0af4ced868f5 60 */
evanso 7:0af4ced868f5 61 void draw_line(N5110 &lcd, int line_length);
evanso 7:0af4ced868f5 62
evanso 27:8bb2bd97c319 63 /** Duplicates the first part of the map to fill the gap when the map
evanso 27:8bb2bd97c319 64 * loops round forwards
evanso 27:8bb2bd97c319 65 * @ param lcd @details N5110 object
evanso 18:11068b98e261 66 */
evanso 11:ab578a151f67 67 void check_duplicates_map_forward(N5110 &lcd);
evanso 11:ab578a151f67 68
evanso 27:8bb2bd97c319 69 /** Duplicates the last part of the map to fill the gap when the map
evanso 27:8bb2bd97c319 70 * loops round backwards
evanso 27:8bb2bd97c319 71 * @ param lcd @details N5110 object
evanso 18:11068b98e261 72 */
evanso 11:ab578a151f67 73 void check_duplicates_map_backwards(N5110 &lcd);
evanso 18:11068b98e261 74
evanso 27:8bb2bd97c319 75 /** Fills random lengths and hights arrays and fills arrays with random
evanso 27:8bb2bd97c319 76 * integers so same random map is drawn each frame
evanso 18:11068b98e261 77 * @param Pad @details : Gampad adc object used to generate seed
evanso 18:11068b98e261 78 */
evanso 18:11068b98e261 79 void fill_random_arrays(Gamepad &pad);
evanso 18:11068b98e261 80
evanso 27:8bb2bd97c319 81 /** Calulates the map movement depeding on spaceship positions and
evanso 27:8bb2bd97c319 82 * joystick input
evanso 27:8bb2bd97c319 83 * @param d_ @details Direction object of joystick
evanso 27:8bb2bd97c319 84 * @retrun inger @details Move map value for map draw function
evanso 18:11068b98e261 85 */
evanso 18:11068b98e261 86 int calc_map_movement(Direction d_);
evanso 11:ab578a151f67 87
evanso 27:8bb2bd97c319 88 // Variables ---------------------------------------------------------------
evanso 7:0af4ced868f5 89
evanso 82:3211b31e9421 90 /** Store random heights triangles */
evanso 27:8bb2bd97c319 91 int rand_heights_[12];
evanso 9:1ddb8dc93e48 92
evanso 82:3211b31e9421 93 /** Store lengths of lines */
evanso 27:8bb2bd97c319 94 int rand_lengths_[12];
evanso 9:1ddb8dc93e48 95
evanso 82:3211b31e9421 96 /** Store the final element used in the random array befor the break
evanso 27:8bb2bd97c319 97 * in draw map
evanso 27:8bb2bd97c319 98 */
evanso 11:ab578a151f67 99 int final_random_element_used_;
evanso 11:ab578a151f67 100
evanso 27:8bb2bd97c319 101 /** Required to reset the map to it's origonal postion at end of each
evanso 27:8bb2bd97c319 102 * frame, as draw line and triangle functions change position_x_map_
evanso 27:8bb2bd97c319 103 */
evanso 27:8bb2bd97c319 104 int reset_position_x_map_to_origonal_;
evanso 24:479da6ca0e7e 105
evanso 27:8bb2bd97c319 106 /** Length of map */
evanso 27:8bb2bd97c319 107 int map_length_;
evanso 6:12e8433382b3 108 };
evanso 6:12e8433382b3 109
evanso 85:87bc28b151d8 110 #endif