Nemesis game, engine
Embed:
(wiki syntax)
Show/hide line numbers
Engine.h
00001 #ifndef ENGINE_H 00002 #define ENGINE_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 #include "Enemy1.h" 00008 #include "Enemy2.h" 00009 #include "Enemy3.h" 00010 #include "Enemy4.h" 00011 #include "Enemy5.h" 00012 #include "Enemy6.h" 00013 #include "Friendly.h" 00014 #include "Rocket.h" 00015 #include "Stats.h" 00016 00017 /** Engine Class 00018 @brief Engine for interfacing with the Nemesis game. Includes drawing, checking, game state-changing methods, 00019 @brief for Friendly and Enemy ships, Weapons, and Stats bar. 00020 @brief Incorporates N5110.h and Gamepad.h files by Craig A. Evans. 00021 00022 @brief Revision 1.0 00023 00024 @author Musallam M. M. Bseiso 00025 @date 3rd May 2017 00026 */ 00027 00028 class Engine 00029 { 00030 00031 public: 00032 00033 /// Constructor and destructor: 00034 Engine(); 00035 ~Engine(); 00036 00037 00038 //////////////////////////////// 00039 //////// PUBLIC VARIABLES 00040 //////////////////////////////// 00041 00042 00043 /// Integer variable that stores the collisions the friendly ship has with the enemy ships: 00044 int collisions; 00045 00046 /// Integer variable that stores the number of the wave the player is currently in (or the number of waves survived): 00047 int wave_counter; 00048 00049 /// Boolean variable that stores if the player has a star available or not: 00050 bool star; 00051 00052 /// Integer variable that stores the number of rockets the player has available: 00053 int ammo; 00054 00055 /// Integer variable that stores the number of pauses the player has available: 00056 int pauses; 00057 00058 /// Boolean variable that stores if a rocket has been shot or not: 00059 bool rocket_shot_trigger; 00060 00061 /// Boolean variable that stores if health has been regenerated or not: 00062 bool health_regen_trigger; 00063 00064 /// Boolean variable that stores if a rocket has been regenerated or not: 00065 bool rocket_regen_trigger; 00066 00067 /// Boolean variable that stores if a star has been regenerated or not: 00068 bool star_regen_trigger; 00069 00070 00071 //////////////////////////////// 00072 //////// PUBLIC METHODS 00073 //////////////////////////////// 00074 00075 00076 /** Initialize Ships 00077 * 00078 * Initializes friendly and enemy ships' velocity (enemies) and x & y positions (both). 00079 * @param speed - velocity of ship 00080 * @param N5110 - nokia LCD library 00081 * @param lcd - pointer to nokia LCD library 00082 * @param Gamepad - gamepad library 00083 * @param pad - pointer to gamepad library 00084 */ 00085 void init(int speed, N5110 &lcd, Gamepad &pad, int _collisions, int _wave_counter, int _ammo, bool _star, int _pauses); 00086 00087 00088 /** Read Input 00089 * 00090 * Reads direction (_d) and magnitude (_mag) from gamepad analog stick. 00091 * @param Gamepad - gamepad library 00092 * @param pad - pointer to gamepad library 00093 */ 00094 void read_input(Gamepad &pad); 00095 00096 00097 /** Draw Elements 00098 * 00099 * Draws grid, health, weapons, wave counter, and friendly and enemy ships onto the LCD 00100 * @param N5110 - nokia LCD library 00101 * @param lcd - pointer to nokia LCD library 00102 */ 00103 void draw_all(N5110 &lcd); 00104 00105 00106 /** Check All 00107 * 00108 * Method that includes all other checking methods 00109 * @param N5110 - nokia LCD library 00110 * @param lcd - pointer to nokia LCD library 00111 * @param Gamepad - gamepad library 00112 * @param pad - pointer to gamepad library 00113 */ 00114 void check_all(N5110 &lcd, Gamepad &pad); 00115 00116 00117 /** Update All 00118 * 00119 * Updates friendly and enemy ship parameters (position), as well as making sure the friendly ship doesn't go off screen 00120 * by limiting its x and y positions. 00121 * @param N5110 - nokia LCD library 00122 * @param lcd - pointer to nokia LCD library 00123 * @param Gamepad - gamepad library 00124 * @param pad - pointer to gamepad library 00125 */ 00126 void update_all(N5110 &lcd, Gamepad &pad); 00127 00128 00129 /** Shoot Rocket 00130 * 00131 * Triggers a rocket to be shot from the friendly ship, destroying enemy ship opposite, at the press of a button (B). 00132 * Checks if rockets ("ammo" variable) available, draws rocket onto screen, triggers "check_enemy_death" method, subtracts 1 from 00133 * "ammo", and outputs a sound. First of two weapon types. 00134 * @param N5110 - nokia LCD library 00135 * @param lcd - pointer to nokia LCD library 00136 * @param Gamepad - gamepad library 00137 * @param pad - pointer to gamepad library 00138 */ 00139 void shoot_rocket(N5110 &lcd, Gamepad &pad); 00140 00141 00142 /** Shoot Star 00143 * 00144 * Triggers a star to be shot from the friendly ship, destroying all enemy ships, at the press of a button (A). 00145 * Checks if star ("star" variable) available, sets "star" to false, and outputs a sound. Second of two weapon types. 00146 * @param N5110 - nokia LCD library 00147 * @param lcd - pointer to nokia LCD library 00148 * @param Gamepad - gamepad library 00149 * @param pad - pointer to gamepad library 00150 */ 00151 void shoot_star(N5110 &lcd, Gamepad &pad); 00152 00153 private: 00154 00155 00156 //////////////////////////////// 00157 //////// PRIVATE VARIABLES 00158 //////////////////////////////// 00159 00160 00161 /// Integer variable that stores the speed of the enemy ships: 00162 int _speed; 00163 00164 /// Variable that stores the direction of the analog stick: 00165 Direction _d; 00166 00167 /// Floating point variable that stores the magnitude of the analog stick movement: 00168 float _mag; 00169 00170 /// Objects created: 00171 Friendly _friendly; 00172 Enemy1 _enemy1; 00173 Enemy2 _enemy2; 00174 Enemy3 _enemy3; 00175 Enemy4 _enemy4; 00176 Enemy5 _enemy5; 00177 Enemy6 _enemy6; 00178 Rocket _rocket; 00179 Stats _stats; 00180 00181 //////////////////////////////// 00182 //////// PRIVATE METHODS 00183 //////////////////////////////// 00184 00185 00186 /** Check Enemy Pass (high) 00187 * 00188 * Reinitializes enemy ships that have passed off-screen (x < 0) to their starting position. As Enemy1 passes, 00189 * increments wave counter (adds 1 to the "wave_counter" variable), then resets rocket and star regeneration 00190 * trigger to false (sets "rocket_regen_trigger" and "star_regen_trigger" to false) to allow further regeneration 00191 * at next wave. This method only deals with reinitializing the upper 3 enemies (Enemy1, Enemy2, and Enemy3). 00192 * @param Gamepad - gamepad library 00193 * @param pad - pointer to gamepad library 00194 */ 00195 void check_enemy_pass_high(Gamepad &pad); 00196 00197 00198 /** Check Enemy Pass (low) 00199 * 00200 * Reinitializes enemy ships that have passed off-screen (x < 0) to their starting position. This method only deals 00201 * with reinitializing the lower 3 enemies (Enemy4, Enemy5, and Enemy6). 00202 * @param Gamepad - gamepad library 00203 * @param pad - pointer to gamepad library 00204 */ 00205 void check_enemy_pass_low(Gamepad &pad); 00206 00207 00208 /** Check Enemy Death (high) 00209 * 00210 * Reinitializes enemy ships that have been shot by a rocket to their starting position. This method only deals with 00211 * reinitializing the upper 3 enemies (Enemy1, Enemy2, and Enemy3). 00212 * @param Gamepad - gamepad library 00213 * @param pad - pointer to gamepad library 00214 */ 00215 void check_enemy_death_high(Gamepad &pad); 00216 00217 00218 /** Check Enemy Death (low) 00219 * 00220 * Reinitializes enemy ships that have been shot by a rocket to their starting position. This method only deals with 00221 * reinitializing the lower 3 enemies (Enemy4, Enemy5, and Enemy6). 00222 * @param Gamepad - gamepad library 00223 * @param pad - pointer to gamepad library 00224 */ 00225 void check_enemy_death_low(Gamepad &pad); 00226 00227 00228 /** Check Friendly Death 00229 * 00230 * Registers friendly collisions with an enemy ship (adds 1 to "collisions" variable). 00231 */ 00232 void check_friendly_death(Gamepad &pad, Vector2D ship_pos); 00233 00234 00235 /** Check Friendly Death All 00236 * 00237 * Method that includes "check_friendly_death" method for all 6 enemy ships. 00238 * @param N5110 - nokia LCD library 00239 * @param lcd - pointer to nokia LCD library 00240 * @param Gamepad - gamepad library 00241 * @param pad - pointer to gamepad library 00242 */ 00243 void check_friendly_death_all(N5110 &lcd, Gamepad &pad); 00244 00245 00246 /** Check Health Replenish 00247 * 00248 * Regenerates health (subtracts 1 to "collisions" variable) at certain waves, if "health_regen_trigger" is false, and 00249 * the player has less than full health already (only executes if "collisions" is non-zero). 00250 * Then sets "health_regen_trigger" to true to prevent excessive health regeneration. 00251 */ 00252 void check_health_replenish(); 00253 00254 00255 /** Check Rocket Replenish 00256 * 00257 * Regenerates rockets (adds 1 to "ammo" variable) at certain waves, if "rocket_regen_trigger" is false, and 00258 * the player has less than 3 rockets already, as the maximum is 3 (only executes if "ammo" is less than 3). 00259 * Then sets "rocket_regen_trigger" to true to prevent excessive rocket regeneration. 00260 */ 00261 void check_rocket_replenish(); 00262 00263 00264 /** Check Star Replenish 00265 * 00266 * Regenerates star (sets "star" variable to true) at certain waves, if "star_regen_trigger" is false, and 00267 * the player does not already have a star, as the maximum is 1 (only executes if "star" is false). Then sets 00268 * "star_regen_trigger" to true to prevent excessive star regeneration. 00269 */ 00270 void check_star_replenish(); 00271 00272 00273 /** Check Level 2 00274 * 00275 * Moves on to level 2 if wave 5 has been reached. A dialog box is drawn onto the LCD, and the player can move on 00276 * to the next level by pressing a button (BACK). Reinitializes the friendly ship at it starting position, and the 00277 * enemy ships at their starting positions at an elevated speed (at LEVEL_TWO, which is defined as 3). 00278 * Sets the wave to 6 (sets "wave_counter" variable to 6). 00279 * @param N5110 - nokia LCD library 00280 * @param lcd - pointer to nokia LCD library 00281 * @param Gamepad - gamepad library 00282 * @param pad - pointer to gamepad library 00283 */ 00284 void check_level_two(N5110 &lcd, Gamepad &pad); 00285 00286 00287 /** Check Level 3 00288 * 00289 * Moves on to level 3 if wave 25 has been reached. A dialog box is drawn onto the LCD, and the player can move on 00290 * to the next level by pressing a button (BACK). Reinitializes the friendly ship at it starting position, and the 00291 * enemy ships at their starting positions at an elevated speed (at LEVEL_THREE, which is defined as 4). 00292 * Sets the wave to 26 (sets "wave_counter" variable to 26). 00293 * @param N5110 - nokia LCD library 00294 * @param lcd - pointer to nokia LCD library 00295 * @param Gamepad - gamepad library 00296 * @param pad - pointer to gamepad library 00297 */ 00298 void check_level_three(N5110 &lcd, Gamepad &pad); 00299 00300 00301 /** Check Level 4 00302 * 00303 * Moves on to level 4 if wave 50 has been reached. A dialog box is drawn onto the LCD, and the player can move on 00304 * to the next level by pressing a button (BACK). Reinitializes the friendly ship at it starting position, and the 00305 * enemy ships at their starting positions at an elevated speed (at LEVEL_FOUR, which is defined as 5). 00306 * Sets the wave to 51 (sets "wave_counter" variable to 51). 00307 * @param N5110 - nokia LCD library 00308 * @param lcd - pointer to nokia LCD library 00309 * @param Gamepad - gamepad library 00310 * @param pad - pointer to gamepad library 00311 */ 00312 void check_level_four(N5110 &lcd, Gamepad &pad); 00313 00314 00315 /** Check Level 5 00316 * 00317 * Moves on to level 5 if wave 100 has been reached. A dialog box is drawn onto the LCD, and the player can move on 00318 * to the next level by pressing a button (BACK). Reinitializes the friendly ship at it starting position, and the 00319 * enemy ships at their starting positions at an elevated speed (at LEVEL_FIVE, which is defined as 6). 00320 * Sets the wave to 101 (sets "wave_counter" variable to 101). 00321 * @param N5110 - nokia LCD library 00322 * @param lcd - pointer to nokia LCD library 00323 * @param Gamepad - gamepad library 00324 * @param pad - pointer to gamepad library 00325 */ 00326 void check_level_five(N5110 &lcd, Gamepad &pad); 00327 00328 00329 /** Check Pause 00330 * 00331 * Pauses the game if a button (START) is pressed, and the player has remaining pauses to use ("pause" variable is > 0). 00332 * Flashes the pad's LEDs and switches the LCD's mode between normal and inverse until a button (START) is pressed again. 00333 * Once unpaused, removes one pause from the player (subtracts 1 from the "pauses" variable). 00334 * @param N5110 - nokia LCD library 00335 * @param lcd - pointer to nokia LCD library 00336 * @param Gamepad - gamepad library 00337 * @param pad - pointer to gamepad library 00338 */ 00339 void check_pause(N5110 &lcd, Gamepad &pad); 00340 00341 00342 /** Check LCD Mode 00343 * 00344 * Toggles 'night' mode (LCD's inverse mode) if a button (LEFT) is pressed. Sets the mode back to normal (LCD's normal mode) 00345 * if a button (RIGHT) is pressed. 00346 * @param N5110 - nokia LCD library 00347 * @param lcd - pointer to nokia LCD library 00348 * @param Gamepad - gamepad library 00349 * @param pad - pointer to gamepad library 00350 */ 00351 void check_mode_toggle(N5110 &lcd, Gamepad &pad); 00352 00353 00354 /** Check for Gameover Sequence 00355 * 00356 * Ends the game if the player has no lives remaining ("collisions" variable is above 5). A dialog box is printed onto the LCD, 00357 * showing the player's score (waves survived). Once a button is pressed (BACK), the friendly ship is reinitialized at its 00358 * starting position, and the enemy ships at their starting positions at the initial speed (at LEVEL_ONE, which is defined as 2). 00359 * @param N5110 - nokia LCD library 00360 * @param lcd - pointer to nokia LCD library 00361 * @param Gamepad - gamepad library 00362 * @param pad - pointer to gamepad library 00363 */ 00364 void check_gameover(N5110 &lcd, Gamepad &pad); 00365 00366 }; 00367 00368 #endif
Generated on Wed Jul 13 2022 19:16:01 by
1.7.2