Ben Evans University Second Year Project. Game Called Defender.
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.
Map/Map.h@13:12276eed13ac, 2020-04-26 (annotated)
- Committer:
- evanso
- Date:
- Sun Apr 26 17:08:10 2020 +0000
- Revision:
- 13:12276eed13ac
- Parent:
- 12:1c0b6796aaca
- Child:
- 14:7419c680656f
Changed spaceship unit test code so it now done properly and doesn't require my input. Changed where objects are defined to reduce the number of arguments that need passing when a function is called. Edited gamepad code to properly add ADC pin.
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 | 13:12276eed13ac | 4 | // Include 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 | 6:12e8433382b3 | 23 | /** Initalises Spaceship */ |
evanso | 13:12276eed13ac | 24 | void init(Gamepad &pad); |
evanso | 11:ab578a151f67 | 25 | |
evanso | 11:ab578a151f67 | 26 | /** 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 |
evanso | 11:ab578a151f67 | 27 | * @param LCD object, move_map variable |
evanso | 11:ab578a151f67 | 28 | */ |
evanso | 11:ab578a151f67 | 29 | void draw_map(N5110 &lcd, int move_map); |
evanso | 11:ab578a151f67 | 30 | |
evanso | 13:12276eed13ac | 31 | // Accessors and mutators ---------------------------------------------- |
evanso | 6:12e8433382b3 | 32 | |
evanso | 11:ab578a151f67 | 33 | /** Gets x postion of the map |
evanso | 11:ab578a151f67 | 34 | * @return maps x postion |
evanso | 11:ab578a151f67 | 35 | */ |
evanso | 11:ab578a151f67 | 36 | int get_position_x_map(); |
evanso | 11:ab578a151f67 | 37 | |
evanso | 11:ab578a151f67 | 38 | private: |
evanso | 13:12276eed13ac | 39 | // Functions prototypes ------------------------------------------------ |
evanso | 11:ab578a151f67 | 40 | |
evanso | 11:ab578a151f67 | 41 | /** Gets 11 random integers for random lengths and hights arrays |
evanso | 11:ab578a151f67 | 42 | * and stores in array so same random ma is drawn each frame |
evanso | 11:ab578a151f67 | 43 | * @param RandGen object |
evanso | 11:ab578a151f67 | 44 | */ |
evanso | 13:12276eed13ac | 45 | void get_random_arrays(Gamepad &pad); |
evanso | 11:ab578a151f67 | 46 | |
evanso | 7:0af4ced868f5 | 47 | /** Draws a triangle from position with specified hight wich represents a mountain of the map |
evanso | 7:0af4ced868f5 | 48 | * @param LCD object, Hight of trangle |
evanso | 7:0af4ced868f5 | 49 | */ |
evanso | 7:0af4ced868f5 | 50 | void draw_triangle(N5110 &lcd, int triangle_hight); |
evanso | 7:0af4ced868f5 | 51 | |
evanso | 7:0af4ced868f5 | 52 | /** Draws a horizontal line with specified length to represent flat land on map |
evanso | 7:0af4ced868f5 | 53 | * @param LCD object, Length of line |
evanso | 7:0af4ced868f5 | 54 | */ |
evanso | 7:0af4ced868f5 | 55 | void draw_line(N5110 &lcd, int line_length); |
evanso | 7:0af4ced868f5 | 56 | |
evanso | 11:ab578a151f67 | 57 | /** Duplicates the first part of the map to fill the gap when the map loops round |
evanso | 11:ab578a151f67 | 58 | * @ param LCD object |
evanso | 8:dd1037c5435b | 59 | */ |
evanso | 11:ab578a151f67 | 60 | void check_duplicates_map_forward(N5110 &lcd); |
evanso | 11:ab578a151f67 | 61 | |
evanso | 11:ab578a151f67 | 62 | /** Duplicates the last part of the map to fill the gap when the map loops round |
evanso | 11:ab578a151f67 | 63 | * @ param LCD object |
evanso | 9:1ddb8dc93e48 | 64 | */ |
evanso | 11:ab578a151f67 | 65 | void check_duplicates_map_backwards(N5110 &lcd); |
evanso | 11:ab578a151f67 | 66 | |
evanso | 13:12276eed13ac | 67 | // Variables ----------------------------------------------------------- |
evanso | 12:1c0b6796aaca | 68 | |
evanso | 12:1c0b6796aaca | 69 | // Map x postion on lcd |
evanso | 11:ab578a151f67 | 70 | int position_x_map_; |
evanso | 7:0af4ced868f5 | 71 | |
evanso | 12:1c0b6796aaca | 72 | // Map y postion on lcd |
evanso | 11:ab578a151f67 | 73 | int position_y_map_; |
evanso | 9:1ddb8dc93e48 | 74 | |
evanso | 12:1c0b6796aaca | 75 | // Float to store random seed for random function |
evanso | 11:ab578a151f67 | 76 | float rand_seed_; |
evanso | 9:1ddb8dc93e48 | 77 | |
evanso | 12:1c0b6796aaca | 78 | // Map length |
evanso | 11:ab578a151f67 | 79 | int map_length_; |
evanso | 11:ab578a151f67 | 80 | |
evanso | 11:ab578a151f67 | 81 | // Arrays to hold random heights of triangles and lengths of lines |
evanso | 11:ab578a151f67 | 82 | int rand_heights_[12]; |
evanso | 7:0af4ced868f5 | 83 | int rand_lengths_[12]; |
evanso | 11:ab578a151f67 | 84 | |
evanso | 11:ab578a151f67 | 85 | // To store the final element used in the random array befor the break in draw map |
evanso | 11:ab578a151f67 | 86 | int final_random_element_used_; |
evanso | 11:ab578a151f67 | 87 | |
evanso | 11:ab578a151f67 | 88 | //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 | 89 | int reset_position_x_map_to_origonal_; |
evanso | 6:12e8433382b3 | 90 | }; |
evanso | 6:12e8433382b3 | 91 | |
evanso | 6:12e8433382b3 | 92 | #endif |