ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Thu May 09 13:22:45 2019 +0000
Revision:
52:29772e31a620
Parent:
51:2231e2e141b9
Child:
53:3fdc4486f672
Add testing and Menu information

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 49:aa204bf7ee2e 80 *@param fps, the frames per second.
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 52:29772e31a620 113
ikenna1 52:29772e31a620 114 private:
ikenna1 52:29772e31a620 115 //_____________________private-Methods________________________________________________________
ikenna1 52:29772e31a620 116 /** An accessor method used to get the current number of the two enemies, seeker and shooter, on screen
ikenna1 52:29772e31a620 117 @returns a 2D vector of the enemy numbers with the .x referring to shooters and the .y referring to seekers
ikenna1 52:29772e31a620 118 */
ikenna1 52:29772e31a620 119 Vector2D get_enemynum();
ikenna1 52:29772e31a620 120 /** A mutator method that updates the ships weapons
ikenna1 52:29772e31a620 121 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 52:29772e31a620 122 */
ikenna1 52:29772e31a620 123 void update_ship_weapon(Gamepad &pad);
ikenna1 52:29772e31a620 124 /** Draws the appropriate ship based on shipUsed (the ship being used)
ikenna1 52:29772e31a620 125 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 52:29772e31a620 126 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 52:29772e31a620 127 */
ikenna1 52:29772e31a620 128 void draw_ship(N5110 &lcd, Gamepad &pad);
ikenna1 52:29772e31a620 129 /** A mutator function that changes ship_width appropriate ship based on shipUsed (the ship being used)
ikenna1 52:29772e31a620 130 */
ikenna1 52:29772e31a620 131 void set_ship_size();
ikenna1 52:29772e31a620 132 /** A mutator function that changes the players score
ikenna1 52:29772e31a620 133 *@param points, the amount of points the player scored
ikenna1 52:29772e31a620 134 */
ikenna1 52:29772e31a620 135 void score(int points);
ikenna1 49:aa204bf7ee2e 136 /** Checks if a seeker and the player ship collided
ikenna1 51:2231e2e141b9 137 *@param &pad address of the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 138 */
ikenna1 35:3341f2bd0408 139 void seeker_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 140 /** Checks if a shooter 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 shooter_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 144 /** Checks if a shooter's projectile 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 shooterw_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 148 /** Checks if the kestrel ships's projectile and the seeker 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 kestrelw_seeker_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 152 /** Checks if the Imperions lazer 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 imperionw_seeker_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 156 /** Checks if the kestrel ships's projectile and the shooter 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 kestrelw_shooter_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 160 /** Checks if the Imperions lazer 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 imperionw_shooter_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 164 /** Checks if the orions weapon collided with any enemy
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 40:90c7a893d513 167 void orionw_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 168 /** Gradually increased the difficulty of the game over time
ikenna1 49:aa204bf7ee2e 169 *@param time_elapsed, the amount of time since the player selected play from menu
ikenna1 49:aa204bf7ee2e 170 */
ikenna1 38:4571537238ed 171 void scaling(float time_elapsed);
ikenna1 49:aa204bf7ee2e 172 /** Generates a random number using the <ctime> library
ikenna1 49:aa204bf7ee2e 173 *@returns a random number
ikenna1 49:aa204bf7ee2e 174 */
ikenna1 37:8d8c8cce0bc7 175 int rand_no();
ikenna1 49:aa204bf7ee2e 176 /** Displays a random tip on lcd
ikenna1 51:2231e2e141b9 177 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 178 */
ikenna1 38:4571537238ed 179 void game_over(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 180 /** Displays the points the player has on screen
ikenna1 51:2231e2e141b9 181 *@param &lcd address of the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 182 */
ikenna1 39:7824f9080f59 183 void disp_points(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 184 /** Checks the seekers health
ikenna1 49:aa204bf7ee2e 185 */
ikenna1 39:7824f9080f59 186 void check_se_health();
ikenna1 49:aa204bf7ee2e 187 /** Checks the shooter health
ikenna1 49:aa204bf7ee2e 188 */
ikenna1 39:7824f9080f59 189 void check_sh_health();
ikenna1 49:aa204bf7ee2e 190 /** Finds the average distance between two points on the 2D screen
ikenna1 49:aa204bf7ee2e 191 *@param x1 the x co-ordinate of the first point
ikenna1 49:aa204bf7ee2e 192 *@param y1 the y co-ordinate of the first point
ikenna1 49:aa204bf7ee2e 193 *@param x2 the x co-ordinate of the second point
ikenna1 49:aa204bf7ee2e 194 *@param y2 the y co-ordinate of the second point
ikenna1 49:aa204bf7ee2e 195 *@returns the distance between the two points
ikenna1 49:aa204bf7ee2e 196 */
ikenna1 40:90c7a893d513 197 int range(int x1, int y1, float x2, float y2);
ikenna1 49:aa204bf7ee2e 198 /** Finds the closest enemy ship to the player's ship on screen
ikenna1 49:aa204bf7ee2e 199 *@ returns the index and distance of closest enemy ship
ikenna1 49:aa204bf7ee2e 200 */
ikenna1 40:90c7a893d513 201 Vector2D find_closest1();
ikenna1 49:aa204bf7ee2e 202 /** An accessor function that finds the position of the closest enemy on screen to ship
ikenna1 49:aa204bf7ee2e 203 *@param index, the index number of the closest ship (0-3) for shooter and (4-6) dor seekers
ikenna1 49:aa204bf7ee2e 204 *@returns the position of the closest enemy
ikenna1 49:aa204bf7ee2e 205 */
ikenna1 40:90c7a893d513 206 Vector2D find_closest2(int index);
ikenna1 51:2231e2e141b9 207 //_______________Private-Variables__________________________________________
ikenna1 52:29772e31a620 208 Ship _ship; // The ship class object
ikenna1 52:29772e31a620 209 Weapons _weapons; // The weapon class object
ikenna1 52:29772e31a620 210 Menu _menu; // The menu class object
ikenna1 52:29772e31a620 211 Enemy _enemy; // The enemy class object
ikenna1 52:29772e31a620 212 Health _health; // The health class object
ikenna1 52:29772e31a620 213 Lore _lore; // The lore class object
ikenna1 51:2231e2e141b9 214 Vector2D _joystick; // a vector containing the joystick values
ikenna1 51:2231e2e141b9 215 Direction _d; // direction of the joystick, N,S,E, or W
ikenna1 51:2231e2e141b9 216 SHIP _shipUsed; // a variable in of type enum SHIP that contains the ship being used by the player
ikenna1 51:2231e2e141b9 217 int _ycursor; // the _ycursor value that indicates where the rectangular cursor is drawn in the menu
ikenna1 51:2231e2e141b9 218 int _score; // the players score
ikenna1 51:2231e2e141b9 219 int _shipWidth; // the ship's width
ikenna1 51:2231e2e141b9 220 int _shipHeight; // the ship's height
ikenna1 51:2231e2e141b9 221 Vector2D _shipPos; // the ships position
ikenna1 51:2231e2e141b9 222 Vector2D _shooterPos[3]; // an array of all the shooter positions
ikenna1 51:2231e2e141b9 223 Vector2D _shooterWPos[3]; // an array of all the shooter weapon positions
ikenna1 51:2231e2e141b9 224 Vector2D _seekerPos[3]; // an array of the seeker position
ikenna1 51:2231e2e141b9 225 bool _dead; // true if player dies else false
ikenna1 51:2231e2e141b9 226 int _times_run; // the amount of times the game loop is run
ikenna1 51:2231e2e141b9 227 int _no_shooters; // the anount of shooters
ikenna1 51:2231e2e141b9 228 int _no_seekers; // the amount of seeker
ikenna1 51:2231e2e141b9 229 bool _intro; // true if intro has been shown else false
ikenna1 51:2231e2e141b9 230 float _wait_time; // amount of time before increasing difficulty
ikenna1 25:faba9eb44514 231
ikenna1 2:66a4e5d7a7cd 232
ikenna1 2:66a4e5d7a7cd 233 };
ikenna1 25:faba9eb44514 234 /************STUFF TO FIX******************************
ikenna1 28:6319e928f0aa 235 **** add sound effects for sjield braking
ikenna1 28:6319e928f0aa 236 **** add passive shield regeneration
ikenna1 29:4c7b16b5b6df 237 **** work on score increase
ikenna1 29:4c7b16b5b6df 238 **** add title screen with name
ikenna1 29:4c7b16b5b6df 239 **** make it so back asks you if you are sure and ststes that you will lose all progress
ikenna1 29:4c7b16b5b6df 240 **** think of level system
ikenna1 29:4c7b16b5b6df 241 **** orion should send out pulses that stun enemy ships and absorb thier shields(use draw line)
ikenna1 29:4c7b16b5b6df 242 **** scale shields properly
ikenna1 29:4c7b16b5b6df 243 **** fix the border issue(i.e the ships clip through healthbar)
ikenna1 30:711d722f3cef 244 **** make it so enemy ship spawning is random use srand
ikenna1 34:6d0786582d81 245 **** add in options for lcd brightness and contrast
ikenna1 34:6d0786582d81 246 **** add in cheats
ikenna1 34:6d0786582d81 247 ****
ikenna1 25:faba9eb44514 248 */
ikenna1 35:3341f2bd0408 249 #endif
ikenna1 35:3341f2bd0408 250 /*
ikenna1 36:c25417f0d150 251 changes not commited
ikenna1 36:c25417f0d150 252 *Fix game playing in background
ikenna1 36:c25417f0d150 253 *Change seeker damage to 175
ikenna1 36:c25417f0d150 254 *make seeker health 5
ikenna1 36:c25417f0d150 255 * implement a viewing system for enemy ships
ikenna1 36:c25417f0d150 256 * enemy comes from below very fast
ikenna1 36:c25417f0d150 257 * if you hold a button shields come up in front but not sides
ikenna1 36:c25417f0d150 258 *
ikenna1 36:c25417f0d150 259 *
ikenna1 35:3341f2bd0408 260 */