ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Thu May 09 06:02:20 2019 +0000
Revision:
50:69fc9b5e3335
Parent:
49:aa204bf7ee2e
Child:
51:2231e2e141b9
Documentation test;

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 49:aa204bf7ee2e 42 *@param &pad pointer to 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 49:aa204bf7ee2e 47 *@param &pad pointer to 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 49:aa204bf7ee2e 51 *@param &lcd pointer to the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 52 *@param &pad pointer to 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 49:aa204bf7ee2e 59 *@param &lcd pointer to 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 *@returns the ship being used
ikenna1 49:aa204bf7ee2e 69 */
ikenna1 43:500b8cff3715 70 SHIP set_shipUsed();
ikenna1 49:aa204bf7ee2e 71 /** Displays the ship option in the menu to allow player switch ships
ikenna1 49:aa204bf7ee2e 72 *@param &lcd pointer to the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 73 */
ikenna1 12:47578eb9ea73 74 void ship_select(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 75 /** A mutator method that checks the enemies and players health. it resets an enemy if
ikenna1 49:aa204bf7ee2e 76 * its health falls to 0 and sets dead to true if the players health falls to 0.
ikenna1 49:aa204bf7ee2e 77 * either the kestrel, the imperion or the orion
ikenna1 49:aa204bf7ee2e 78 */
ikenna1 36:c25417f0d150 79 void check_health();
ikenna1 49:aa204bf7ee2e 80 /** Calulates the amount of time past in seconds
ikenna1 49:aa204bf7ee2e 81 *@param fps, the frames per second.
ikenna1 49:aa204bf7ee2e 82 */
ikenna1 38:4571537238ed 83 float timer(int fps);
ikenna1 49:aa204bf7ee2e 84 /** An accessor method that returns true when a player dies
ikenna1 49:aa204bf7ee2e 85 */
ikenna1 38:4571537238ed 86 bool dead();
ikenna1 49:aa204bf7ee2e 87 /** Displays the intro to the game
ikenna1 49:aa204bf7ee2e 88 *@param &lcd pointer to the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 89 */
ikenna1 39:7824f9080f59 90 void intro(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 91 /** An accessor method used to get the current number of the two enemies, seeker and shooter, on screen
ikenna1 49:aa204bf7ee2e 92 @returns a 2D vector of the enemy numbers with the .x referring to shooters and the .y referring to seekers
ikenna1 49:aa204bf7ee2e 93 */
ikenna1 40:90c7a893d513 94 Vector2D get_enemynum();
ikenna1 30:711d722f3cef 95
ikenna1 25:faba9eb44514 96 //*** note: add ship width and ship heirgth in place of 6 and 9 to generalize arrays after they are finished
ikenna1 10:c33d7593a275 97
ikenna1 2:66a4e5d7a7cd 98 private:
ikenna1 49:aa204bf7ee2e 99 /** A mutator method that updates the shooters projectile position
ikenna1 49:aa204bf7ee2e 100 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 101 */
ikenna1 41:e1fa36c0492e 102 void update_shooter_weapon(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 103 /** Draws the appropriate ship based on shipUsed (the ship being used)
ikenna1 49:aa204bf7ee2e 104 *@param &lcd pointer to the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 105 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 106 */
ikenna1 41:e1fa36c0492e 107 void draw_ship(N5110 &lcd, Gamepad &pad);
ikenna1 49:aa204bf7ee2e 108 /** A mutator function that changes ship_width appropriate ship based on shipUsed (the ship being used)
ikenna1 49:aa204bf7ee2e 109 */
ikenna1 41:e1fa36c0492e 110 void set_ship_size();
ikenna1 49:aa204bf7ee2e 111 /** A mutator function that changes the players score
ikenna1 49:aa204bf7ee2e 112 *@param points, the amount of points the player scored
ikenna1 49:aa204bf7ee2e 113 */
ikenna1 30:711d722f3cef 114 void score(int points);
ikenna1 49:aa204bf7ee2e 115 /** Checks for a collision between two 2D objects
ikenna1 49:aa204bf7ee2e 116 *@param xpos1, the x co-ordinate of the first object
ikenna1 49:aa204bf7ee2e 117 *@param ypos1, the y co-ordinate of the first object
ikenna1 49:aa204bf7ee2e 118 *@param width1, the width of the first object
ikenna1 49:aa204bf7ee2e 119 *@param height1, the height of the first object
ikenna1 49:aa204bf7ee2e 120 *@param xpos2, the x co-ordinate of the second object
ikenna1 49:aa204bf7ee2e 121 *@param ypos2, the y co-ordinate of the second object
ikenna1 49:aa204bf7ee2e 122 *@param width2, the width of the second object
ikenna1 49:aa204bf7ee2e 123 *@param height2, the height of the second object
ikenna1 49:aa204bf7ee2e 124 */
ikenna1 35:3341f2bd0408 125 bool check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2);
ikenna1 49:aa204bf7ee2e 126 /** Checks if two objects positione intersect across a vertical line
ikenna1 49:aa204bf7ee2e 127 *used for the imperion weapon collisions
ikenna1 49:aa204bf7ee2e 128 *@param xpos1, the x co-ordinate of the first object
ikenna1 49:aa204bf7ee2e 129 *@param width1, the width of the first object
ikenna1 49:aa204bf7ee2e 130 *@param xpos2, the x co-ordinate of the second object
ikenna1 49:aa204bf7ee2e 131 *@param width2, the width of the second object
ikenna1 49:aa204bf7ee2e 132 */
ikenna1 35:3341f2bd0408 133 bool check_collision1(int xpos1,int width1,int xpos2,int width2);
ikenna1 49:aa204bf7ee2e 134 /** Checks if a seeker and the player ship collided
ikenna1 49:aa204bf7ee2e 135 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 136 */
ikenna1 35:3341f2bd0408 137 void seeker_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 138 /** Checks if a shooter and the player ship collided
ikenna1 49:aa204bf7ee2e 139 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 140 */
ikenna1 35:3341f2bd0408 141 void shooter_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 142 /** Checks if a shooter's projectile and the player ship collided
ikenna1 49:aa204bf7ee2e 143 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 144 */
ikenna1 35:3341f2bd0408 145 void shooterw_ship_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 146 /** Checks if the kestrel ships's projectile and the seeker collided
ikenna1 49:aa204bf7ee2e 147 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 148 */
ikenna1 35:3341f2bd0408 149 void kestrelw_seeker_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 150 /** Checks if the Imperions lazer and the seeker collided
ikenna1 49:aa204bf7ee2e 151 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 152 */
ikenna1 35:3341f2bd0408 153 void imperionw_seeker_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 154 /** Checks if the kestrel ships's projectile and the shooter collided
ikenna1 49:aa204bf7ee2e 155 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 156 */
ikenna1 35:3341f2bd0408 157 void kestrelw_shooter_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 158 /** Checks if the Imperions lazer and the shooter collided
ikenna1 49:aa204bf7ee2e 159 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 160 */
ikenna1 35:3341f2bd0408 161 void imperionw_shooter_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 162 /** Checks if the orions weapon collided with any enemy
ikenna1 49:aa204bf7ee2e 163 *@param &pad pointer to the gamepad library used to read inputs and send outputs to the gamepad
ikenna1 49:aa204bf7ee2e 164 */
ikenna1 40:90c7a893d513 165 void orionw_collision(Gamepad &pad);
ikenna1 49:aa204bf7ee2e 166 /** Gradually increased the difficulty of the game over time
ikenna1 49:aa204bf7ee2e 167 *@param time_elapsed, the amount of time since the player selected play from menu
ikenna1 49:aa204bf7ee2e 168 */
ikenna1 38:4571537238ed 169 void scaling(float time_elapsed);
ikenna1 49:aa204bf7ee2e 170 /** Generates a random number using the <ctime> library
ikenna1 49:aa204bf7ee2e 171 *@returns a random number
ikenna1 49:aa204bf7ee2e 172 */
ikenna1 37:8d8c8cce0bc7 173 int rand_no();
ikenna1 49:aa204bf7ee2e 174 /** Displays a random tip on lcd
ikenna1 49:aa204bf7ee2e 175 *@param &lcd pointer to the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 176 */
ikenna1 38:4571537238ed 177 void game_over(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 178 /** Displays the points the player has on screen
ikenna1 49:aa204bf7ee2e 179 *@param &lcd pointer to the N5110 library used for the lcd display
ikenna1 49:aa204bf7ee2e 180 */
ikenna1 39:7824f9080f59 181 void disp_points(N5110 &lcd);
ikenna1 49:aa204bf7ee2e 182 /** Checks the seekers health
ikenna1 49:aa204bf7ee2e 183 */
ikenna1 39:7824f9080f59 184 void check_se_health();
ikenna1 49:aa204bf7ee2e 185 /** Checks the shooter health
ikenna1 49:aa204bf7ee2e 186 */
ikenna1 39:7824f9080f59 187 void check_sh_health();
ikenna1 49:aa204bf7ee2e 188 /** Finds the average distance between two points on the 2D screen
ikenna1 49:aa204bf7ee2e 189 *@param x1 the x co-ordinate of the first point
ikenna1 49:aa204bf7ee2e 190 *@param y1 the y co-ordinate of the first point
ikenna1 49:aa204bf7ee2e 191 *@param x2 the x co-ordinate of the second point
ikenna1 49:aa204bf7ee2e 192 *@param y2 the y co-ordinate of the second point
ikenna1 49:aa204bf7ee2e 193 *@returns the distance between the two points
ikenna1 49:aa204bf7ee2e 194 */
ikenna1 40:90c7a893d513 195 int range(int x1, int y1, float x2, float y2);
ikenna1 49:aa204bf7ee2e 196 /** Finds the closest enemy ship to the player's ship on screen
ikenna1 49:aa204bf7ee2e 197 *@ returns the index and distance of closest enemy ship
ikenna1 49:aa204bf7ee2e 198 */
ikenna1 40:90c7a893d513 199 Vector2D find_closest1();
ikenna1 49:aa204bf7ee2e 200 /** An accessor function that finds the position of the closest enemy on screen to ship
ikenna1 49:aa204bf7ee2e 201 *@param index, the index number of the closest ship (0-3) for shooter and (4-6) dor seekers
ikenna1 49:aa204bf7ee2e 202 *@returns the position of the closest enemy
ikenna1 49:aa204bf7ee2e 203 */
ikenna1 40:90c7a893d513 204 Vector2D find_closest2(int index);
ikenna1 4:740e14ebbc97 205
ikenna1 36:c25417f0d150 206
ikenna1 4:740e14ebbc97 207 // Variables
ikenna1 43:500b8cff3715 208
ikenna1 8:87a845b8575e 209 Ship _ship;
ikenna1 9:241a1a7d8527 210 Weapons _weapons;
ikenna1 9:241a1a7d8527 211 Menu _menu;
ikenna1 15:009ccc07bb57 212 Enemy _enemy;
ikenna1 17:e65a9f981834 213 Health _health;
ikenna1 39:7824f9080f59 214 Lore _lore;
ikenna1 41:e1fa36c0492e 215 Vector2D _joystick;
ikenna1 9:241a1a7d8527 216 Direction _d;
ikenna1 43:500b8cff3715 217 SHIP _shipUsed;
ikenna1 10:c33d7593a275 218 int _ycursor;
ikenna1 21:628fb703188f 219 int _shipno;
ikenna1 30:711d722f3cef 220 int _score;
ikenna1 34:6d0786582d81 221 int _shno;
ikenna1 41:e1fa36c0492e 222 int _shipWidth;
ikenna1 41:e1fa36c0492e 223 int _shipHeight;
ikenna1 41:e1fa36c0492e 224 Vector2D _shipPos;
ikenna1 41:e1fa36c0492e 225 Vector2D _shooterPos[3];
ikenna1 41:e1fa36c0492e 226 Vector2D _shooterWPos[3];
ikenna1 41:e1fa36c0492e 227 Vector2D _seekerPos[3];
ikenna1 34:6d0786582d81 228 Vector2D _coloc;
ikenna1 36:c25417f0d150 229 bool _dead;
ikenna1 38:4571537238ed 230 int _times_run;
ikenna1 38:4571537238ed 231 int _no_shooters;
ikenna1 39:7824f9080f59 232 int _no_seekers;
ikenna1 39:7824f9080f59 233 bool _intro;
ikenna1 39:7824f9080f59 234 float _wait_time;
ikenna1 25:faba9eb44514 235
ikenna1 2:66a4e5d7a7cd 236
ikenna1 2:66a4e5d7a7cd 237 };
ikenna1 25:faba9eb44514 238 /************STUFF TO FIX******************************
ikenna1 28:6319e928f0aa 239 **** add sound effects for sjield braking
ikenna1 28:6319e928f0aa 240 **** add passive shield regeneration
ikenna1 29:4c7b16b5b6df 241 **** work on score increase
ikenna1 29:4c7b16b5b6df 242 **** add title screen with name
ikenna1 29:4c7b16b5b6df 243 **** make it so back asks you if you are sure and ststes that you will lose all progress
ikenna1 29:4c7b16b5b6df 244 **** think of level system
ikenna1 29:4c7b16b5b6df 245 **** orion should send out pulses that stun enemy ships and absorb thier shields(use draw line)
ikenna1 29:4c7b16b5b6df 246 **** scale shields properly
ikenna1 29:4c7b16b5b6df 247 **** fix the border issue(i.e the ships clip through healthbar)
ikenna1 30:711d722f3cef 248 **** make it so enemy ship spawning is random use srand
ikenna1 34:6d0786582d81 249 **** add in options for lcd brightness and contrast
ikenna1 34:6d0786582d81 250 **** add in cheats
ikenna1 34:6d0786582d81 251 ****
ikenna1 25:faba9eb44514 252 */
ikenna1 35:3341f2bd0408 253 #endif
ikenna1 35:3341f2bd0408 254 /*
ikenna1 36:c25417f0d150 255 changes not commited
ikenna1 36:c25417f0d150 256 *Fix game playing in background
ikenna1 36:c25417f0d150 257 *Change seeker damage to 175
ikenna1 36:c25417f0d150 258 *make seeker health 5
ikenna1 36:c25417f0d150 259 * implement a viewing system for enemy ships
ikenna1 36:c25417f0d150 260 * enemy comes from below very fast
ikenna1 36:c25417f0d150 261 * if you hold a button shields come up in front but not sides
ikenna1 36:c25417f0d150 262 *
ikenna1 36:c25417f0d150 263 *
ikenna1 35:3341f2bd0408 264 */