Joshua O'hara 201291390

Dependencies:   mbed

Committer:
josh_ohara
Date:
Tue May 26 15:15:46 2020 +0000
Revision:
44:3b904d25ee12
Parent:
43:1ac200335a68
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
josh_ohara 9:8e695df3cc36 1 #include "mbed.h"
josh_ohara 9:8e695df3cc36 2 #include "N5110.h"
josh_ohara 9:8e695df3cc36 3 #include "Gamepad.h"
josh_ohara 42:816e444e660b 4 #include "AlienBulletVector.h"
josh_ohara 33:d8284dee58db 5 #include "PowerUp.h"
josh_ohara 35:517b56b010df 6 #include <vector>
josh_ohara 2:c2316b659b97 7
josh_ohara 38:6f50b548226e 8 /** Alien Class
josh_ohara 38:6f50b548226e 9 @author Joshua Ohara, el18jkeo, 201291390
josh_ohara 38:6f50b548226e 10 @brief Controls the aliens
josh_ohara 38:6f50b548226e 11 @date May 2020
josh_ohara 38:6f50b548226e 12 */
josh_ohara 38:6f50b548226e 13
josh_ohara 9:8e695df3cc36 14 class Alien
josh_ohara 9:8e695df3cc36 15 {
josh_ohara 9:8e695df3cc36 16 public:
josh_ohara 38:6f50b548226e 17
josh_ohara 38:6f50b548226e 18 /**Initialise private variables to starting values*/
josh_ohara 38:6f50b548226e 19 void init(int x, int y, int size, int level); //initialise alien object and set private variables
josh_ohara 38:6f50b548226e 20
josh_ohara 38:6f50b548226e 21 /**Draw alien object if alive at current x and y position*/
josh_ohara 38:6f50b548226e 22 void render(N5110 &lcd); //draw aliens
josh_ohara 38:6f50b548226e 23
josh_ohara 38:6f50b548226e 24 /**Update private variables and flags*/
josh_ohara 38:6f50b548226e 25 void update(int step_x, int remainder_x, Gamepad &pad, int counter, int level); //update private variables (position, shoot value)
josh_ohara 38:6f50b548226e 26
josh_ohara 38:6f50b548226e 27 /**Chance to set shoot flag on everage every 8 game loop iterations
josh_ohara 38:6f50b548226e 28 *by creating a random number and testing if it is within certain limit,
josh_ohara 38:6f50b548226e 29 *if it does, shoot flag is set and alien will shoot, limit becomes broader
josh_ohara 38:6f50b548226e 30 *as level increases so that aliens will shoot more
josh_ohara 38:6f50b548226e 31 *@param _shoot (bool)
josh_ohara 38:6f50b548226e 32 */
josh_ohara 38:6f50b548226e 33 void shoot_flag_set(int counter, int level); //set the shoot flag
josh_ohara 38:6f50b548226e 34
josh_ohara 27:eb755a345b1f 35 //Accessors and Mutators
josh_ohara 38:6f50b548226e 36
josh_ohara 38:6f50b548226e 37 /**Sets the alien's life value
josh_ohara 38:6f50b548226e 38 *@param _life (bool)
josh_ohara 38:6f50b548226e 39 */
josh_ohara 38:6f50b548226e 40 void set_life(bool x); //set the aliens life
josh_ohara 38:6f50b548226e 41
josh_ohara 38:6f50b548226e 42 /**Returns the alien's life value
josh_ohara 38:6f50b548226e 43 *@return _life (bool)
josh_ohara 38:6f50b548226e 44 */
josh_ohara 38:6f50b548226e 45 bool get_life(); //returns the alien life
josh_ohara 38:6f50b548226e 46
josh_ohara 38:6f50b548226e 47 /**Returns a 2D vector of alien's x and y position
josh_ohara 38:6f50b548226e 48 *@return position (Vector2D)
josh_ohara 38:6f50b548226e 49 */
josh_ohara 38:6f50b548226e 50 Vector2D get_position(); //returns 2D vector of alien x and y position
josh_ohara 38:6f50b548226e 51
josh_ohara 38:6f50b548226e 52 /**Returns the alien's vector of alien bullets
josh_ohara 38:6f50b548226e 53 *@return _alien_bullet_vector (vector<AlienBullet>)
josh_ohara 38:6f50b548226e 54 */
josh_ohara 38:6f50b548226e 55 vector<AlienBullet> get_bullet_vector(); //returns a copy of this aliens bullet vector
josh_ohara 38:6f50b548226e 56
josh_ohara 38:6f50b548226e 57 /**Sets the hit value of bullet i in the alien's vector of alien bullets
josh_ohara 38:6f50b548226e 58 *@param bullet hit (bool)
josh_ohara 38:6f50b548226e 59 */
josh_ohara 38:6f50b548226e 60 void set_bullet_hit(int i, bool hit); //sets the hit value of bullet i in this aliens vector of bullets
josh_ohara 38:6f50b548226e 61
josh_ohara 38:6f50b548226e 62 /**Sets the value of the power flag and the create powerup flag if alien is
josh_ohara 38:6f50b548226e 63 *not alive, create powerup flag can only be set once when alien dies as
josh_ohara 38:6f50b548226e 64 *powerup flag is set to false
josh_ohara 38:6f50b548226e 65 *@param _powerup (bool)
josh_ohara 38:6f50b548226e 66 *@param _create_powerup (bool)
josh_ohara 38:6f50b548226e 67 */
josh_ohara 43:1ac200335a68 68 void create_powerup_flag_set(); //sets powerup flag that allows powerup to be created
josh_ohara 38:6f50b548226e 69
josh_ohara 38:6f50b548226e 70 /**Returns the hit value of a powerup that has been deployed
josh_ohara 38:6f50b548226e 71 *@return powerup hit (bool)
josh_ohara 38:6f50b548226e 72 */
josh_ohara 43:1ac200335a68 73 bool get_powerup_hit(); //returns powerup hit value if created
josh_ohara 38:6f50b548226e 74
josh_ohara 38:6f50b548226e 75 /**Sets the value of the powerup hit value
josh_ohara 38:6f50b548226e 76 *@param powerup hit (bool)
josh_ohara 38:6f50b548226e 77 */
josh_ohara 43:1ac200335a68 78 void set_powerup_hit(bool x); //sets the hit value of powerup if created
josh_ohara 38:6f50b548226e 79
josh_ohara 38:6f50b548226e 80 /**Returns a 2D vector containing the powerup x and y position
josh_ohara 38:6f50b548226e 81 *@return powerup position (Vector2D)
josh_ohara 38:6f50b548226e 82 */
josh_ohara 43:1ac200335a68 83 Vector2D get_powerup_position(); //returns 2D vector of powerups position if created
josh_ohara 2:c2316b659b97 84
josh_ohara 10:9189419fda68 85 private:
josh_ohara 38:6f50b548226e 86 int _x; //x position of the alien
josh_ohara 38:6f50b548226e 87 int _y; //y position of the alien
josh_ohara 38:6f50b548226e 88 bool _alive; //bool value of if alien is alive
josh_ohara 38:6f50b548226e 89 int _speed; //alien speed in x direction
josh_ohara 38:6f50b548226e 90 float _size; //alien size
josh_ohara 38:6f50b548226e 91 bool _shoot; //shoot flag (if shoot is true alien can shoot)
josh_ohara 43:1ac200335a68 92 bool _powerup; //powerup flag (allows powerup to be shot)
josh_ohara 43:1ac200335a68 93 bool _create_powerup; //flag to show both that a powerup should be created and that a powerup has been created
josh_ohara 43:1ac200335a68 94 AlienBulletVector _alien_bullet_vector; //alien's vector of bullets
josh_ohara 43:1ac200335a68 95 vector<PowerUp> _powerup_vector; //aliens vector of powerups, making powerup accessible to rest of class
josh_ohara 33:d8284dee58db 96 };