Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

Committer:
evanso
Date:
Mon May 25 18:39:51 2020 +0000
Revision:
82:3211b31e9421
Parent:
27:8bb2bd97c319
Child:
85:87bc28b151d8
Made commenting and formatting of code more consistent.

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