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.
Alien/Alien.h@86:eecd168c3a23, 2020-05-27 (annotated)
- 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?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| evanso | 19:1bc0a2d22054 | 1 | #ifndef ALIEN_H | 
| evanso | 19:1bc0a2d22054 | 2 | #define ALIEN_H | 
| evanso | 19:1bc0a2d22054 | 3 | |
| evanso | 82:3211b31e9421 | 4 | // Included Headers ------------------------------------------------------------ | 
| evanso | 19:1bc0a2d22054 | 5 | #include "mbed.h" | 
| evanso | 19:1bc0a2d22054 | 6 | #include "N5110.h" | 
| evanso | 28:a5958497d5ce | 7 | #include "RandomMovement.h" | 
| evanso | 35:577c65bf914e | 8 | #include "CheckCollision.h" | 
| evanso | 19:1bc0a2d22054 | 9 | |
| evanso | 20:febd920ec29e | 10 | /** Alien class | 
| evanso | 27:8bb2bd97c319 | 11 | * @brief Draws and moves aliens | 
| evanso | 27:8bb2bd97c319 | 12 | * @author Benjamin Evans, University of Leeds | 
| evanso | 27:8bb2bd97c319 | 13 | * @date May 2020 | 
| evanso | 27:8bb2bd97c319 | 14 | */ | 
| evanso | 35:577c65bf914e | 15 | class Alien: public RandomMovement, public CheckCollision { | 
| evanso | 19:1bc0a2d22054 | 16 | public: | 
| evanso | 19:1bc0a2d22054 | 17 | /** Constructor */ | 
| evanso | 19:1bc0a2d22054 | 18 | Alien(); | 
| evanso | 19:1bc0a2d22054 | 19 | |
| evanso | 19:1bc0a2d22054 | 20 | /** Destructor */ | 
| evanso | 19:1bc0a2d22054 | 21 | ~Alien(); | 
| evanso | 19:1bc0a2d22054 | 22 | |
| evanso | 85:87bc28b151d8 | 23 | /** Initialises Alien | 
| evanso | 32:c006a9882778 | 24 | * @param position_x_start @details Random x start pos of alien | 
| evanso | 32:c006a9882778 | 25 | * @param position_y_start @details Random y start pos of alien | 
| evanso | 82:3211b31e9421 | 26 | * @param pad @details Gamepad object | 
| evanso | 32:c006a9882778 | 27 | */ | 
| evanso | 32:c006a9882778 | 28 | void init(Gamepad &pad, int position_x_start, int position_y_start); | 
| evanso | 20:febd920ec29e | 29 | |
| evanso | 20:febd920ec29e | 30 | /** Draws the alien | 
| evanso | 27:8bb2bd97c319 | 31 | * @param lcd @details N5110 object | 
| evanso | 27:8bb2bd97c319 | 32 | * @param spaceship_pos @details xy spaceship position | 
| evanso | 27:8bb2bd97c319 | 33 | * @param d_ @details Direction of joystick | 
| evanso | 27:8bb2bd97c319 | 34 | * @param map_length_ @details length of map | 
| evanso | 27:8bb2bd97c319 | 35 | * @param position_x_map_ @details x position of map | 
| evanso | 85:87bc28b151d8 | 36 | * @param alien_collision @details bool if a collision happened | 
| evanso | 20:febd920ec29e | 37 | */ | 
| evanso | 27:8bb2bd97c319 | 38 | void draw_alien(N5110 &lcd, Vector2D spaceship_pos, Direction d_, | 
| evanso | 34:85ccc16f24d2 | 39 | int map_length_, int position_x_map_, bool alien_collision); | 
| evanso | 19:1bc0a2d22054 | 40 | |
| evanso | 21:f7d7834e3af1 | 41 | // Accessors and mutators -------------------------------------------------- | 
| evanso | 20:febd920ec29e | 42 | |
| evanso | 31:6015e8ed859c | 43 | /** Gets the counter for alien time to fire | 
| evanso | 31:6015e8ed859c | 44 | * @return alien_fire_counter_ | 
| evanso | 22:053c11a202e1 | 45 | */ | 
| evanso | 31:6015e8ed859c | 46 | int get_alien_fire_counter(); | 
| evanso | 28:a5958497d5ce | 47 | |
| evanso | 82:3211b31e9421 | 48 | /** Sets the position_x_ of alien | 
| evanso | 33:7fedd8029473 | 49 | * @param position_x | 
| evanso | 33:7fedd8029473 | 50 | */ | 
| evanso | 33:7fedd8029473 | 51 | void set_alien_x_pos(int position_x); | 
| evanso | 33:7fedd8029473 | 52 | |
| evanso | 82:3211b31e9421 | 53 | /** Sets the collision_people_element number | 
| evanso | 34:85ccc16f24d2 | 54 | * @param people_element | 
| evanso | 34:85ccc16f24d2 | 55 | */ | 
| evanso | 34:85ccc16f24d2 | 56 | void set_collision_people_element(int people_element); | 
| evanso | 34:85ccc16f24d2 | 57 | |
| evanso | 85:87bc28b151d8 | 58 | /** Gets the collision_people_element number | 
| evanso | 34:85ccc16f24d2 | 59 | * @return collision_people_element | 
| evanso | 34:85ccc16f24d2 | 60 | */ | 
| evanso | 34:85ccc16f24d2 | 61 | int get_collision_people_element(); | 
| evanso | 34:85ccc16f24d2 | 62 | |
| evanso | 82:3211b31e9421 | 63 | /** Sets alien track_flag | 
| evanso | 34:85ccc16f24d2 | 64 | * @param track_flag_ | 
| evanso | 34:85ccc16f24d2 | 65 | */ | 
| evanso | 34:85ccc16f24d2 | 66 | void set_track_flag(bool track_flag); | 
| evanso | 34:85ccc16f24d2 | 67 | |
| evanso | 40:71f947254fda | 68 | /** Gets alien track_flag | 
| evanso | 40:71f947254fda | 69 | * @return track_flag_ | 
| evanso | 40:71f947254fda | 70 | */ | 
| evanso | 40:71f947254fda | 71 | bool get_track_flag(); | 
| evanso | 40:71f947254fda | 72 | |
| evanso | 19:1bc0a2d22054 | 73 | private: | 
| evanso | 19:1bc0a2d22054 | 74 | // Function prototypes ----------------------------------------------------- | 
| evanso | 21:f7d7834e3af1 | 75 | |
| evanso | 21:f7d7834e3af1 | 76 | /** Moves the alien towards the spaceship and around the map | 
| evanso | 21:f7d7834e3af1 | 77 | * @param spaceship_pos @details : Position of the spaceship | 
| evanso | 21:f7d7834e3af1 | 78 | */ | 
| evanso | 24:479da6ca0e7e | 79 | void move_hunt_mode(Vector2D spaceship_pos); | 
| evanso | 19:1bc0a2d22054 | 80 | |
| evanso | 27:8bb2bd97c319 | 81 | /** Stops the alien from moving off the edge of the map and moves alien | 
| evanso | 27:8bb2bd97c319 | 82 | * if the map loops | 
| evanso | 24:479da6ca0e7e | 83 | * @param map_length_@details : length of the map | 
| evanso | 27:8bb2bd97c319 | 84 | * @param position_x_map_ @detials : the drawing start posisiton of the | 
| evanso | 27:8bb2bd97c319 | 85 | * map | 
| evanso | 24:479da6ca0e7e | 86 | */ | 
| evanso | 24:479da6ca0e7e | 87 | void off_screen_x_y_checker(int map_length_, int position_x_map_); | 
| evanso | 24:479da6ca0e7e | 88 | |
| evanso | 19:1bc0a2d22054 | 89 | // Variables --------------------------------------------------------------- | 
| evanso | 19:1bc0a2d22054 | 90 | |
| evanso | 27:8bb2bd97c319 | 91 | /** Alien movement counter */ | 
| evanso | 28:a5958497d5ce | 92 | int alien_move_counter_; | 
| evanso | 28:a5958497d5ce | 93 | |
| evanso | 28:a5958497d5ce | 94 | /** Alien fire bullet counter */ | 
| evanso | 34:85ccc16f24d2 | 95 | int alien_fire_counter_; | 
| evanso | 34:85ccc16f24d2 | 96 | |
| evanso | 34:85ccc16f24d2 | 97 | /** People element that alien as collided with */ | 
| evanso | 34:85ccc16f24d2 | 98 | int collision_people_element_; | 
| evanso | 34:85ccc16f24d2 | 99 | |
| evanso | 85:87bc28b151d8 | 100 | /** Alien abducted people and now track spaceship flag */ | 
| evanso | 34:85ccc16f24d2 | 101 | bool track_flag_; | 
| evanso | 28:a5958497d5ce | 102 | |
| evanso | 19:1bc0a2d22054 | 103 | }; | 
| evanso | 19:1bc0a2d22054 | 104 | |
| evanso | 85:87bc28b151d8 | 105 | #endif |