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@9:1ddb8dc93e48, 2020-04-21 (annotated)
- Committer:
- evanso
- Date:
- Tue Apr 21 23:13:19 2020 +0000
- Revision:
- 9:1ddb8dc93e48
- Parent:
- 8:dd1037c5435b
- Child:
- 11:ab578a151f67
Made the map loop back on its self when you reach the ends, therefore the map never ends
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 | 6:12e8433382b3 | 4 | // Include libraries |
evanso | 6:12e8433382b3 | 5 | #include "mbed.h" |
evanso | 6:12e8433382b3 | 6 | #include "N5110.h" |
evanso | 6:12e8433382b3 | 7 | #include "Gamepad.h" |
evanso | 6:12e8433382b3 | 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 | 8:dd1037c5435b | 24 | void init(AnalogIn &adc); |
evanso | 6:12e8433382b3 | 25 | |
evanso | 7:0af4ced868f5 | 26 | /** Draws a triangle from position with specified hight wich represents a mountain of the map |
evanso | 7:0af4ced868f5 | 27 | * @param LCD object, Hight of trangle |
evanso | 7:0af4ced868f5 | 28 | */ |
evanso | 7:0af4ced868f5 | 29 | void draw_triangle(N5110 &lcd, int triangle_hight); |
evanso | 7:0af4ced868f5 | 30 | |
evanso | 7:0af4ced868f5 | 31 | /** Draws a horizontal line with specified length to represent flat land on map |
evanso | 7:0af4ced868f5 | 32 | * @param LCD object, Length of line |
evanso | 7:0af4ced868f5 | 33 | */ |
evanso | 7:0af4ced868f5 | 34 | void draw_line(N5110 &lcd, int line_length); |
evanso | 7:0af4ced868f5 | 35 | |
evanso | 7:0af4ced868f5 | 36 | /** Gets 12 random integers between 5 and 12 for the random heights of triangles |
evanso | 7:0af4ced868f5 | 37 | * and stores in an array so same random map is drawn when screen refreshesh |
evanso | 8:dd1037c5435b | 38 | * @param ADC signal input object |
evanso | 7:0af4ced868f5 | 39 | * @return random hieght of the traingle |
evanso | 6:12e8433382b3 | 40 | */ |
evanso | 9:1ddb8dc93e48 | 41 | void get_random_height_array(AnalogIn &adc); |
evanso | 7:0af4ced868f5 | 42 | |
evanso | 7:0af4ced868f5 | 43 | /** Gets 12 random integers between 15 and 30 for the random lengths of lines |
evanso | 7:0af4ced868f5 | 44 | * and stores in an array so same random map is drawn when screen refreshesh |
evanso | 8:dd1037c5435b | 45 | * @return random length of lines |
evanso | 8:dd1037c5435b | 46 | * @param ADC signal input object |
evanso | 8:dd1037c5435b | 47 | */ |
evanso | 8:dd1037c5435b | 48 | void get_random_length_array(AnalogIn &adc); |
evanso | 7:0af4ced868f5 | 49 | |
evanso | 9:1ddb8dc93e48 | 50 | /** 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 | 9:1ddb8dc93e48 | 51 | * @param LCD object, move_map variable |
evanso | 9:1ddb8dc93e48 | 52 | */ |
evanso | 7:0af4ced868f5 | 53 | void draw_map(N5110 &lcd, int move_map); |
evanso | 7:0af4ced868f5 | 54 | |
evanso | 8:dd1037c5435b | 55 | /** Gets x postion of the map |
evanso | 9:1ddb8dc93e48 | 56 | * @return maps x postion |
evanso | 9:1ddb8dc93e48 | 57 | */ |
evanso | 7:0af4ced868f5 | 58 | int get_position_x_map(); |
evanso | 7:0af4ced868f5 | 59 | |
evanso | 9:1ddb8dc93e48 | 60 | /** Duplicates the first part of the map to fill the gap when the map loops round |
evanso | 9:1ddb8dc93e48 | 61 | * @ param LCD object, move_map variable |
evanso | 9:1ddb8dc93e48 | 62 | */ |
evanso | 9:1ddb8dc93e48 | 63 | void check_duplicates_map_forward(N5110 &lcd, int move_map); |
evanso | 9:1ddb8dc93e48 | 64 | |
evanso | 9:1ddb8dc93e48 | 65 | |
evanso | 9:1ddb8dc93e48 | 66 | /** Duplicates the last part of the map to fill the gap when the map loops round |
evanso | 9:1ddb8dc93e48 | 67 | * @ param LCD object, move_map variable |
evanso | 9:1ddb8dc93e48 | 68 | */ |
evanso | 9:1ddb8dc93e48 | 69 | void check_duplicates_map_backwards(N5110 &lcd, int move_map); |
evanso | 9:1ddb8dc93e48 | 70 | |
evanso | 6:12e8433382b3 | 71 | private: |
evanso | 6:12e8433382b3 | 72 | int position_x_map_; |
evanso | 6:12e8433382b3 | 73 | int position_y_map_; |
evanso | 7:0af4ced868f5 | 74 | float rand_seed_; |
evanso | 9:1ddb8dc93e48 | 75 | int rand_heights_[12]; |
evanso | 7:0af4ced868f5 | 76 | int rand_lengths_[12]; |
evanso | 9:1ddb8dc93e48 | 77 | int map_length_; |
evanso | 9:1ddb8dc93e48 | 78 | int final_random_element_used_; |
evanso | 9:1ddb8dc93e48 | 79 | int reset_position_x_map_to_origonal_; |
evanso | 6:12e8433382b3 | 80 | }; |
evanso | 6:12e8433382b3 | 81 | |
evanso | 6:12e8433382b3 | 82 | #endif |