ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jkeo

Dependencies:   mbed

Committer:
josh_ohara
Date:
Mon May 25 14:15:50 2020 +0000
Revision:
37:90a0671d2ba7
Parent:
36:78efa0e7bd31
Child:
42:816e444e660b
Deoxygen test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
josh_ohara 8:86cb9a9f8a73 1 #ifndef SHIP_H
josh_ohara 8:86cb9a9f8a73 2 #define SHIP_H
josh_ohara 2:c2316b659b97 3
josh_ohara 3:8a140aa1ddcd 4 #include "mbed.h"
josh_ohara 3:8a140aa1ddcd 5 #include "N5110.h"
josh_ohara 3:8a140aa1ddcd 6 #include "Gamepad.h"
josh_ohara 21:970807533b10 7 #include "BulletS.h"
josh_ohara 2:c2316b659b97 8
josh_ohara 25:823b1a997a0c 9 /** Ship Class
josh_ohara 25:823b1a997a0c 10 @author Joshua Ohara, el18jkeo, 201291390
josh_ohara 25:823b1a997a0c 11 @brief Controls the ship
josh_ohara 25:823b1a997a0c 12 @date May 2020
josh_ohara 25:823b1a997a0c 13 */
josh_ohara 25:823b1a997a0c 14
josh_ohara 2:c2316b659b97 15 class Ship
josh_ohara 2:c2316b659b97 16 {
josh_ohara 2:c2316b659b97 17
josh_ohara 2:c2316b659b97 18 public:
josh_ohara 37:90a0671d2ba7 19
josh_ohara 37:90a0671d2ba7 20 /** Constructor */
josh_ohara 8:86cb9a9f8a73 21 Ship();
josh_ohara 37:90a0671d2ba7 22
josh_ohara 37:90a0671d2ba7 23 /** Destructor */
josh_ohara 8:86cb9a9f8a73 24 ~Ship();
josh_ohara 37:90a0671d2ba7 25
josh_ohara 37:90a0671d2ba7 26 /** Initialise private member variables to starting values*/
josh_ohara 37:90a0671d2ba7 27 void init(int height, int width); //initialises ship object, sets private variables
josh_ohara 37:90a0671d2ba7 28
josh_ohara 37:90a0671d2ba7 29 /**Draws ship object at current x and y position*/
josh_ohara 37:90a0671d2ba7 30 void render(N5110 &lcd); //draws ship if alive
josh_ohara 37:90a0671d2ba7 31
josh_ohara 37:90a0671d2ba7 32 /**Update the position and shoot flag of the ship based on joystick position*/
josh_ohara 37:90a0671d2ba7 33 void update(Direction d, float mag, Gamepad &pad, N5110 &lcd, int counter, bool powerup); //updates the position and shooting of the ship
josh_ohara 37:90a0671d2ba7 34
josh_ohara 37:90a0671d2ba7 35 /**Sets the life value of the ship object, true is alive false is dead
josh_ohara 37:90a0671d2ba7 36 *@param the life value (bool)
josh_ohara 37:90a0671d2ba7 37 */
josh_ohara 37:90a0671d2ba7 38 void set_life(bool life); //sets the life of the ship
josh_ohara 37:90a0671d2ba7 39
josh_ohara 37:90a0671d2ba7 40 /**Returns the value of the life to check for collisions
josh_ohara 37:90a0671d2ba7 41 *@return life value (bool)
josh_ohara 37:90a0671d2ba7 42 */
josh_ohara 37:90a0671d2ba7 43 bool get_life(); //returns the life of the ship
josh_ohara 37:90a0671d2ba7 44
josh_ohara 37:90a0671d2ba7 45 /**Sets the hit value of bullet i in this ship's vector of bullets, true is hit has occurred, false it has not
josh_ohara 37:90a0671d2ba7 46 *@param bullet hit (bool)
josh_ohara 37:90a0671d2ba7 47 */
josh_ohara 37:90a0671d2ba7 48 void set_bullet_hit(int i, bool hit); //sets the life of a given ship bullet (hit if a collsion occurs)
josh_ohara 37:90a0671d2ba7 49
josh_ohara 37:90a0671d2ba7 50 /**Returns a 2D vector containing the x and y position of the ship
josh_ohara 37:90a0671d2ba7 51 *@return ship position (Vector2D)
josh_ohara 37:90a0671d2ba7 52 */
josh_ohara 37:90a0671d2ba7 53 Vector2D get_position(); //returns the position of the ship for collision check
josh_ohara 37:90a0671d2ba7 54
josh_ohara 37:90a0671d2ba7 55 /**Returns a copy of this ship's vector of ship bullets
josh_ohara 37:90a0671d2ba7 56 *@return ship's bullet vector (vector<ShipBullet>)
josh_ohara 37:90a0671d2ba7 57 */
josh_ohara 37:90a0671d2ba7 58 vector<ShipBullet> get_bullet_vector(); //returns the ship bullet vector for collsion check
josh_ohara 2:c2316b659b97 59
josh_ohara 2:c2316b659b97 60 private:
josh_ohara 37:90a0671d2ba7 61 int _height; //height of the ship main rectangle
josh_ohara 37:90a0671d2ba7 62 int _width; //width of the ship main rectangle
josh_ohara 37:90a0671d2ba7 63 int _x; //x posittion of ship
josh_ohara 37:90a0671d2ba7 64 int _y; //y position of the ship
josh_ohara 37:90a0671d2ba7 65 int _speed; //speed of the ship in x direction
josh_ohara 37:90a0671d2ba7 66 bool _powerup; //powerup flag of ship
josh_ohara 37:90a0671d2ba7 67 bool _life; //whether the ship is alive or not
josh_ohara 37:90a0671d2ba7 68 BulletS _ship_bullet_vector; //object to create ship bullet vector
josh_ohara 2:c2316b659b97 69 };
josh_ohara 8:86cb9a9f8a73 70
josh_ohara 8:86cb9a9f8a73 71 #endif