ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Thu May 09 14:52:52 2019 +0000
Revision:
53:3fdc4486f672
Parent:
52:29772e31a620
Final Submission

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ikenna1 2:66a4e5d7a7cd 1 #ifndef ROSENENGINE_H
ikenna1 2:66a4e5d7a7cd 2 #define ROSENENGINE_H
ikenna1 2:66a4e5d7a7cd 3
ikenna1 2:66a4e5d7a7cd 4 #include "mbed.h"
ikenna1 37:8d8c8cce0bc7 5 #include <ctime>
ikenna1 2:66a4e5d7a7cd 6 #include "N5110.h"
ikenna1 2:66a4e5d7a7cd 7 #include "Gamepad.h"
ikenna1 7:ed5870cfb3e0 8 #include "Ship.h"
ikenna1 9:241a1a7d8527 9 #include "Weapons.h"
ikenna1 9:241a1a7d8527 10 #include "Menu.h"
ikenna1 15:009ccc07bb57 11 #include "Enemy.h"
ikenna1 17:e65a9f981834 12 #include "Health.h"
ikenna1 39:7824f9080f59 13 #include "Lore.h"
ikenna1 2:66a4e5d7a7cd 14
ikenna1 50:69fc9b5e3335 15 /** RosenEngine Class
ikenna1 49:aa204bf7ee2e 16 @brief Library that used all other game libraries in order to make game functions
ikenna1 49:aa204bf7ee2e 17 @author Ozoemena Adrian Ikrnna
ikenna1 49:aa204bf7ee2e 18 @date 8th May 2019
ikenna1 49:aa204bf7ee2e 19 */
ikenna1 2:66a4e5d7a7cd 20 class RosenEngine
ikenna1 2:66a4e5d7a7cd 21 {
ikenna1 2:66a4e5d7a7cd 22
ikenna1 2:66a4e5d7a7cd 23 public:
ikenna1 50:69fc9b5e3335 24 /** constructor */
ikenna1 2:66a4e5d7a7cd 25 RosenEngine();
ikenna1 50:69fc9b5e3335 26 /** deconstructor */
ikenna1 2:66a4e5d7a7cd 27 ~RosenEngine();
ikenna1 3:f9cd1a38d5c6 28
ikenna1 49:aa204bf7ee2e 29 /** A mutator method that initializes ship size and speed, the default ship is the kestrel
ikenna1 49:aa204bf7ee2e 30 *@param ship_width, the width of the ship
ikenna1 49:aa204bf7ee2e 31 *@param ship_height, the height of the ship
ikenna1 49:aa204bf7ee2e 32 *@param ship_speed, the speed of the ship
ikenna1 49:aa204bf7ee2e 33 *@param ship_xpos, the ship's x co-ordinate
ikenna1 49:aa204bf7ee2e 34 *@param ship_ypos, the ship's y co-ordinate
ikenna1 49:aa204bf7ee2e 35 */
ikenna1 8:87a845b8575e 36 void init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos);
ikenna1 49:aa204bf7ee2e 37 /** A mutator method that resets some key values that neet to be reinitialized when the player
ikenna1 49:aa204bf7ee2e 38 *returns to the ment
ikenna1 49:aa204bf7ee2e 39 */
ikenna1 27:f99249e727fd 40 void reset();
ikenna1 49:aa204bf7ee2e 41 /** An accessor method that reads the input from the gamepad
ikenna1 51:2231e2e141b9 42 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 43 */
ikenna1 2:66a4e5d7a7cd 44 void read_input(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 45 /** A mutator method that updates all position and variable values based on inputs and the
ikenna1 49:aa204bf7ee2e 46 * time that has passed
ikenna1 51:2231e2e141b9 47 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 48 */
ikenna1 2:66a4e5d7a7cd 49 void update(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 50 /** Draws all game assets on lcd display
ikenna1 51:2231e2e141b9 51 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 51:2231e2e141b9 52 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 53 */
ikenna1 14:88ca5b1a111a 54 void draw(N5110 &lcd, Gamepad &pad);
ikenna1 49:aa204bf7ee2e 55 /** An accessor method that gets the position of all important game objects on screen
ikenna1 49:aa204bf7ee2e 56 */
ikenna1 9:241a1a7d8527 57 void get_pos();
ikenna1 49:aa204bf7ee2e 58 /** Displays the title screen on the lcd
ikenna1 51:2231e2e141b9 59 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 60 */
ikenna1 10:c33d7593a275 61 void title(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 62 /** An accessor method that gets the ycursor value to be used in the menu
ikenna1 49:aa204bf7ee2e 63 *@returns the ycursor value
ikenna1 49:aa204bf7ee2e 64 */
ikenna1 13:e114d362186d 65 int get_ycursor();
ikenna1 49:aa204bf7ee2e 66 /** A mutator method used to set the ship being used in the game.
ikenna1 49:aa204bf7ee2e 67 * either the kestrel, the imperion or the orion
ikenna1 49:aa204bf7ee2e 68 */
ikenna1 52:29772e31a620 69 void set_shipUsed();
ikenna1 49:aa204bf7ee2e 70 /** Displays the ship option in the menu to allow player switch ships
ikenna1 51:2231e2e141b9 71 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 72 */
ikenna1 12:47578eb9ea73 73 void ship_select(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 74 /** A mutator method that checks the enemies and players health. it resets an enemy if
ikenna1 49:aa204bf7ee2e 75 * its health falls to 0 and sets dead to true if the players health falls to 0.
ikenna1 49:aa204bf7ee2e 76 * either the kestrel, the imperion or the orion
ikenna1 49:aa204bf7ee2e 77 */
ikenna1 36:c25417f0d150 78 void check_health();
ikenna1 49:aa204bf7ee2e 79 /** Calulates the amount of time past in seconds
ikenna1 53:3fdc4486f672 80 *@param fps the frames per second that is set
ikenna1 49:aa204bf7ee2e 81 */
ikenna1 38:4571537238ed 82 float timer(int fps);
ikenna1 49:aa204bf7ee2e 83 /** An accessor method that returns true when a player dies
ikenna1 49:aa204bf7ee2e 84 */
ikenna1 38:4571537238ed 85 bool dead();
ikenna1 49:aa204bf7ee2e 86 /** Displays the intro to the game
ikenna1 51:2231e2e141b9 87 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 88 */
ikenna1 39:7824f9080f59 89 void intro(N5110 &lcd);
ikenna1 52:29772e31a620 90 /** An accessor method that gets the ships position
ikenna1 52:29772e31a620 91 *@returns the ships position
ikenna1 49:aa204bf7ee2e 92 */
ikenna1 52:29772e31a620 93 Vector2D get_shipPos();
ikenna1 49:aa204bf7ee2e 94 /** Checks for a collision between two 2D objects
ikenna1 49:aa204bf7ee2e 95 *@param xpos1, the x co-ordinate of the first object
ikenna1 49:aa204bf7ee2e 96 *@param ypos1, the y co-ordinate of the first object
ikenna1 49:aa204bf7ee2e 97 *@param width1, the width of the first object
ikenna1 49:aa204bf7ee2e 98 *@param height1, the height of the first object
ikenna1 49:aa204bf7ee2e 99 *@param xpos2, the x co-ordinate of the second object
ikenna1 49:aa204bf7ee2e 100 *@param ypos2, the y co-ordinate of the second object
ikenna1 49:aa204bf7ee2e 101 *@param width2, the width of the second object
ikenna1 49:aa204bf7ee2e 102 *@param height2, the height of the second object
ikenna1 49:aa204bf7ee2e 103 */
ikenna1 35:3341f2bd0408 104 bool check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2);
ikenna1 49:aa204bf7ee2e 105 /** Checks if two objects positione intersect across a vertical line
ikenna1 49:aa204bf7ee2e 106 *used for the imperion weapon collisions
ikenna1 49:aa204bf7ee2e 107 *@param xpos1, the x co-ordinate of the first object
ikenna1 49:aa204bf7ee2e 108 *@param width1, the width of the first object
ikenna1 49:aa204bf7ee2e 109 *@param xpos2, the x co-ordinate of the second object
ikenna1 49:aa204bf7ee2e 110 *@param width2, the width of the second object
ikenna1 49:aa204bf7ee2e 111 */
ikenna1 35:3341f2bd0408 112 bool check_collision1(int xpos1,int width1,int xpos2,int width2);
ikenna1 53:3fdc4486f672 113 /** Displays help option
ikenna1 53:3fdc4486f672 114 **@param &lcd address of the N5110 library used for the lcd display
ikenna1 53:3fdc4486f672 115 */
ikenna1 53:3fdc4486f672 116 void help(N5110 &lcd);
ikenna1 52:29772e31a620 117
ikenna1 52:29772e31a620 118 private:
ikenna1 52:29772e31a620 119 //_____________________private-Methods________________________________________________________
ikenna1 52:29772e31a620 120 /** An accessor method used to get the current number of the two enemies, seeker and shooter, on screen
ikenna1 52:29772e31a620 121 @returns a 2D vector of the enemy numbers with the .x referring to shooters and the .y referring to seekers
ikenna1 52:29772e31a620 122 */
ikenna1 52:29772e31a620 123 Vector2D get_enemynum();
ikenna1 52:29772e31a620 124 /** A mutator method that updates the ships weapons
ikenna1 52:29772e31a620 125 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 52:29772e31a620 126 */
ikenna1 52:29772e31a620 127 void update_ship_weapon(Gamepad &pad);
ikenna1 52:29772e31a620 128 /** Draws the appropriate ship based on shipUsed (the ship being used)
ikenna1 52:29772e31a620 129 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 52:29772e31a620 130 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 52:29772e31a620 131 */
ikenna1 52:29772e31a620 132 void draw_ship(N5110 &lcd, Gamepad &pad);
ikenna1 52:29772e31a620 133 /** A mutator function that changes ship_width appropriate ship based on shipUsed (the ship being used)
ikenna1 52:29772e31a620 134 */
ikenna1 52:29772e31a620 135 void set_ship_size();
ikenna1 52:29772e31a620 136 /** A mutator function that changes the players score
ikenna1 52:29772e31a620 137 *@param points, the amount of points the player scored
ikenna1 52:29772e31a620 138 */
ikenna1 52:29772e31a620 139 void score(int points);
ikenna1 49:aa204bf7ee2e 140 /** Checks if a seeker and the player ship collided
ikenna1 51:2231e2e141b9 141 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 142 */
ikenna1 35:3341f2bd0408 143 void seeker_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 144 /** Checks if a shooter and the player ship collided
ikenna1 51:2231e2e141b9 145 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 146 */
ikenna1 35:3341f2bd0408 147 void shooter_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 148 /** Checks if a shooter's projectile and the player ship collided
ikenna1 51:2231e2e141b9 149 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 150 */
ikenna1 35:3341f2bd0408 151 void shooterw_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 152 /** Checks if the kestrel ships's projectile and the seeker collided
ikenna1 51:2231e2e141b9 153 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 154 */
ikenna1 35:3341f2bd0408 155 void kestrelw_seeker_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 156 /** Checks if the Imperions lazer and the seeker collided
ikenna1 51:2231e2e141b9 157 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 158 */
ikenna1 35:3341f2bd0408 159 void imperionw_seeker_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 160 /** Checks if the kestrel ships's projectile and the shooter collided
ikenna1 51:2231e2e141b9 161 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 162 */
ikenna1 35:3341f2bd0408 163 void kestrelw_shooter_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 164 /** Checks if the Imperions lazer and the shooter collided
ikenna1 51:2231e2e141b9 165 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 166 */
ikenna1 35:3341f2bd0408 167 void imperionw_shooter_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 168 /** Checks if the orions weapon collided with any enemy
ikenna1 51:2231e2e141b9 169 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 170 */
ikenna1 40:90c7a893d513 171 void orionw_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 172 /** Gradually increased the difficulty of the game over time
ikenna1 49:aa204bf7ee2e 173 *@param time_elapsed, the amount of time since the player selected play from menu
ikenna1 49:aa204bf7ee2e 174 */
ikenna1 38:4571537238ed 175 void scaling(float time_elapsed);
ikenna1 49:aa204bf7ee2e 176 /** Generates a random number using the <ctime> library
ikenna1 49:aa204bf7ee2e 177 *@returns a random number
ikenna1 49:aa204bf7ee2e 178 */
ikenna1 37:8d8c8cce0bc7 179 int rand_no();
ikenna1 49:aa204bf7ee2e 180 /** Displays a random tip on lcd
ikenna1 51:2231e2e141b9 181 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 182 */
ikenna1 38:4571537238ed 183 void game_over(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 184 /** Displays the points the player has on screen
ikenna1 51:2231e2e141b9 185 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 186 */
ikenna1 39:7824f9080f59 187 void disp_points(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 188 /** Checks the seekers health
ikenna1 49:aa204bf7ee2e 189 */
ikenna1 39:7824f9080f59 190 void check_se_health();
ikenna1 49:aa204bf7ee2e 191 /** Checks the shooter health
ikenna1 49:aa204bf7ee2e 192 */
ikenna1 39:7824f9080f59 193 void check_sh_health();
ikenna1 49:aa204bf7ee2e 194 /** Finds the average distance between two points on the 2D screen
ikenna1 49:aa204bf7ee2e 195 *@param x1 the x co-ordinate of the first point
ikenna1 49:aa204bf7ee2e 196 *@param y1 the y co-ordinate of the first point
ikenna1 49:aa204bf7ee2e 197 *@param x2 the x co-ordinate of the second point
ikenna1 49:aa204bf7ee2e 198 *@param y2 the y co-ordinate of the second point
ikenna1 49:aa204bf7ee2e 199 *@returns the distance between the two points
ikenna1 49:aa204bf7ee2e 200 */
ikenna1 40:90c7a893d513 201 int range(int x1, int y1, float x2, float y2);
ikenna1 49:aa204bf7ee2e 202 /** Finds the closest enemy ship to the player's ship on screen
ikenna1 49:aa204bf7ee2e 203 *@ returns the index and distance of closest enemy ship
ikenna1 49:aa204bf7ee2e 204 */
ikenna1 40:90c7a893d513 205 Vector2D find_closest1();
ikenna1 49:aa204bf7ee2e 206 /** An accessor function that finds the position of the closest enemy on screen to ship
ikenna1 49:aa204bf7ee2e 207 *@param index, the index number of the closest ship (0-3) for shooter and (4-6) dor seekers
ikenna1 49:aa204bf7ee2e 208 *@returns the position of the closest enemy
ikenna1 49:aa204bf7ee2e 209 */
ikenna1 40:90c7a893d513 210 Vector2D find_closest2(int index);
ikenna1 51:2231e2e141b9 211 //_______________Private-Variables__________________________________________
ikenna1 52:29772e31a620 212 Ship _ship; // The ship class object
ikenna1 52:29772e31a620 213 Weapons _weapons; // The weapon class object
ikenna1 52:29772e31a620 214 Menu _menu; // The menu class object
ikenna1 52:29772e31a620 215 Enemy _enemy; // The enemy class object
ikenna1 52:29772e31a620 216 Health _health; // The health class object
ikenna1 52:29772e31a620 217 Lore _lore; // The lore class object
ikenna1 51:2231e2e141b9 218 Vector2D _joystick; // a vector containing the joystick values
ikenna1 51:2231e2e141b9 219 Direction _d; // direction of the joystick, N,S,E, or W
ikenna1 51:2231e2e141b9 220 SHIP _shipUsed; // a variable in of type enum SHIP that contains the ship being used by the player
ikenna1 51:2231e2e141b9 221 int _ycursor; // the _ycursor value that indicates where the rectangular cursor is drawn in the menu
ikenna1 51:2231e2e141b9 222 int _score; // the players score
ikenna1 51:2231e2e141b9 223 int _shipWidth; // the ship's width
ikenna1 51:2231e2e141b9 224 int _shipHeight; // the ship's height
ikenna1 51:2231e2e141b9 225 Vector2D _shipPos; // the ships position
ikenna1 51:2231e2e141b9 226 Vector2D _shooterPos[3]; // an array of all the shooter positions
ikenna1 51:2231e2e141b9 227 Vector2D _shooterWPos[3]; // an array of all the shooter weapon positions
ikenna1 51:2231e2e141b9 228 Vector2D _seekerPos[3]; // an array of the seeker position
ikenna1 51:2231e2e141b9 229 bool _dead; // true if player dies else false
ikenna1 51:2231e2e141b9 230 int _times_run; // the amount of times the game loop is run
ikenna1 51:2231e2e141b9 231 int _no_shooters; // the anount of shooters
ikenna1 51:2231e2e141b9 232 int _no_seekers; // the amount of seeker
ikenna1 51:2231e2e141b9 233 bool _intro; // true if intro has been shown else false
ikenna1 51:2231e2e141b9 234 float _wait_time; // amount of time before increasing difficulty
ikenna1 2:66a4e5d7a7cd 235
ikenna1 2:66a4e5d7a7cd 236 };
ikenna1 53:3fdc4486f672 237
ikenna1 35:3341f2bd0408 238 #endif