ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

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