Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Fri May 22 13:02:26 2020 +0000
Revision:
69:753ba27325ce
Parent:
68:bb1650c657ef
Child:
71:bcbac2cfe005
Finished settings class and added it to into game engine.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 11:ab578a151f67 1 #ifndef GAMEENGINE_H
evanso 11:ab578a151f67 2 #define GAMEENGINE_H
evanso 7:0af4ced868f5 3
evanso 27:8bb2bd97c319 4 // Included libraries ----------------------------------------------------------
evanso 7:0af4ced868f5 5 #include "mbed.h"
evanso 7:0af4ced868f5 6 #include "N5110.h"
evanso 7:0af4ced868f5 7 #include "Gamepad.h"
evanso 8:dd1037c5435b 8 #include "Spaceship.h"
evanso 8:dd1037c5435b 9 #include "Map.h"
evanso 17:25d79cca203a 10 #include "Weapons.h"
evanso 19:1bc0a2d22054 11 #include "Alien.h"
evanso 25:70b55f5bfc87 12 #include "Explosion.h"
evanso 33:7fedd8029473 13 #include "People.h"
evanso 39:fc5586b930e3 14 #include "HUD.h"
evanso 40:71f947254fda 15 #include "Menu.h"
evanso 47:49fa1adc10b4 16 #include "FXOS8700CQ.h"
evanso 49:ed569eceeaa4 17 #include "SDFileSystem.h"
evanso 56:663d0546c235 18 #include "SavedGames.h"
evanso 69:753ba27325ce 19 #include "Settings.h"
evanso 67:a2984682d641 20
evanso 67:a2984682d641 21 #include <vector>
evanso 47:49fa1adc10b4 22
evanso 11:ab578a151f67 23 /** GameEngine class
evanso 27:8bb2bd97c319 24 * @brief Runs the different parts of the game
evanso 27:8bb2bd97c319 25 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 26 * @date April 2020
evanso 27:8bb2bd97c319 27 */
evanso 7:0af4ced868f5 28 class GameEngine {
evanso 7:0af4ced868f5 29 public:
evanso 7:0af4ced868f5 30 /** Constructor */
evanso 7:0af4ced868f5 31 GameEngine();
evanso 7:0af4ced868f5 32
evanso 7:0af4ced868f5 33 /** Destructor */
evanso 7:0af4ced868f5 34 ~GameEngine();
evanso 7:0af4ced868f5 35
evanso 14:7419c680656f 36 /** Initalises GameEngine */
evanso 13:12276eed13ac 37 void init();
evanso 7:0af4ced868f5 38
evanso 47:49fa1adc10b4 39 /** Switch statement to run run different menu options */
evanso 42:3aed75338272 40 void game_select_part();
evanso 15:90b6821bcf64 41
evanso 27:8bb2bd97c319 42 // Accessors and mutators --------------------------------------------------
evanso 11:ab578a151f67 43
evanso 11:ab578a151f67 44 private:
evanso 27:8bb2bd97c319 45 // Function prototypes -----------------------------------------------------
evanso 64:e9dfc35a1738 46
evanso 41:5959256f4aab 47 // Menu Control
evanso 64:e9dfc35a1738 48 /** Runs the menu */
evanso 64:e9dfc35a1738 49 void run_menu();
evanso 64:e9dfc35a1738 50
evanso 64:e9dfc35a1738 51 // Menu Play
evanso 64:e9dfc35a1738 52 /** Runs the play game */
evanso 64:e9dfc35a1738 53 void run_play();
evanso 42:3aed75338272 54
evanso 64:e9dfc35a1738 55 /** Initialises the play part of the game*/
evanso 64:e9dfc35a1738 56 void play_init();
evanso 64:e9dfc35a1738 57
evanso 42:3aed75338272 58 /** Main gameplay loop that runs playable part of game */
evanso 42:3aed75338272 59 void gameplay_loop();
evanso 41:5959256f4aab 60
evanso 64:e9dfc35a1738 61 /** Draws the game over screen*/
evanso 64:e9dfc35a1738 62 void draw_game_over_screen();
evanso 41:5959256f4aab 63
evanso 56:663d0546c235 64 /** Runs the paused screen */
evanso 56:663d0546c235 65 void run_paused_game();
evanso 56:663d0546c235 66
evanso 55:c04568b25617 67 /** Draws the pause screen*/
evanso 55:c04568b25617 68 void draw_pause_screen();
evanso 55:c04568b25617 69
evanso 64:e9dfc35a1738 70 /** Runs saved games screen */
evanso 64:e9dfc35a1738 71 void run_saved_games();
evanso 64:e9dfc35a1738 72
evanso 64:e9dfc35a1738 73 /** Time-triggered interrupt to wake MCU from sleep */
evanso 64:e9dfc35a1738 74 void lcd_frame_time_isr();
evanso 57:d4ce42c24561 75
evanso 64:e9dfc35a1738 76 // Menu Setting
evanso 64:e9dfc35a1738 77 /** Runs settings screen*/
evanso 64:e9dfc35a1738 78 void run_settings();
evanso 58:a9a39424df52 79
evanso 64:e9dfc35a1738 80 // Menu Saved Games
evanso 59:0b2e43312d6b 81 /** Initialises the play part of the game and sets the variables to
evanso 59:0b2e43312d6b 82 * saved values
evanso 59:0b2e43312d6b 83 */
evanso 64:e9dfc35a1738 84 void saved_games_overide_init();
evanso 59:0b2e43312d6b 85
evanso 62:f0c86a854a9e 86 /** Runs save a game screen */
evanso 64:e9dfc35a1738 87 void run_save_a_game();
evanso 62:f0c86a854a9e 88
evanso 39:fc5586b930e3 89 //Spaceship Control
evanso 27:8bb2bd97c319 90 /** Gets joystick direction from gamepad and stores it in d_ */
evanso 18:11068b98e261 91 void read_joystick_direction();
evanso 11:ab578a151f67 92
evanso 47:49fa1adc10b4 93 /** Gets the pitch and roll of the gamepad and calculates d_ */
evanso 65:daa792a09e1f 94 void read_accelerometer_direction(float roll, float pitch);
evanso 47:49fa1adc10b4 95
evanso 39:fc5586b930e3 96 /** Turns on specific leds depending on how many lives left */
evanso 39:fc5586b930e3 97 void spaceship_lives_leds();
evanso 39:fc5586b930e3 98
evanso 36:27aa597db3d2 99 //Weapon Control
evanso 39:fc5586b930e3 100 /** Creates weapons object if button A is pressed and stores in vector*/
evanso 36:27aa597db3d2 101 void create_weapons_bullets();
evanso 36:27aa597db3d2 102
evanso 36:27aa597db3d2 103 /** Creates smart bomb if button B is pressed */
evanso 36:27aa597db3d2 104 void create_weapons_smart_bomb();
evanso 19:1bc0a2d22054 105
evanso 27:8bb2bd97c319 106 /** Draws each bullet object and deleted object after set movement
evanso 27:8bb2bd97c319 107 * distance
evanso 27:8bb2bd97c319 108 */
evanso 19:1bc0a2d22054 109 void draw_bullets();
evanso 13:12276eed13ac 110
evanso 36:27aa597db3d2 111 //Alien Control
evanso 36:27aa597db3d2 112 /** Spawns aliens in random position of the screen*/
evanso 36:27aa597db3d2 113 void spawn_aliens();
evanso 36:27aa597db3d2 114
evanso 22:053c11a202e1 115 /** Creats alien object and stores in vector*/
evanso 20:febd920ec29e 116 void create_alien();
evanso 20:febd920ec29e 117
evanso 36:27aa597db3d2 118 /** Checks for alien people collision and sets abduction movements
evanso 36:27aa597db3d2 119 * @param i @details iterator from draw_alien for loop
evanso 36:27aa597db3d2 120 */
evanso 36:27aa597db3d2 121 void check_alien_people_collision(int i);
evanso 36:27aa597db3d2 122
evanso 36:27aa597db3d2 123 /** Gets alien to fire bullets randomley towards spaceship
evanso 36:27aa597db3d2 124 * @param i @details iterator from draw_alien for loop
evanso 36:27aa597db3d2 125 */
evanso 36:27aa597db3d2 126 void alliens_fire_bullets(int i);
evanso 36:27aa597db3d2 127
evanso 36:27aa597db3d2 128 /**Deletes bullet and alien if collision detected and draws explosion
evanso 36:27aa597db3d2 129 * @param i @details iterator from draw_alien for loop
evanso 36:27aa597db3d2 130 */
evanso 36:27aa597db3d2 131 void delete_aliens(int i);
evanso 36:27aa597db3d2 132
evanso 27:8bb2bd97c319 133 /** Draws each alien object and deletes both objects if collision
evanso 27:8bb2bd97c319 134 * detected
evanso 27:8bb2bd97c319 135 */
evanso 20:febd920ec29e 136 void draw_aliens();
evanso 20:febd920ec29e 137
evanso 36:27aa597db3d2 138 //Explotion Control
evanso 36:27aa597db3d2 139 /** Creates bullet object if button A is pressed and stores in vector */
evanso 29:e96d91f1d39c 140 void create_explosion(Vector2D destroyed_position);
evanso 25:70b55f5bfc87 141
evanso 27:8bb2bd97c319 142 /** Draws each explosion object if collision detected */
evanso 25:70b55f5bfc87 143 void draw_explosions();
evanso 25:70b55f5bfc87 144
evanso 36:27aa597db3d2 145 //People Control
evanso 36:27aa597db3d2 146 /** Spawns people in random places at bottom of screen */
evanso 36:27aa597db3d2 147 void spawn_people();
evanso 32:c006a9882778 148
evanso 33:7fedd8029473 149 /** Spawns people in random position at bottom of the screen*/
evanso 33:7fedd8029473 150 void create_people();
evanso 33:7fedd8029473 151
evanso 33:7fedd8029473 152 /** Draws each people object */
evanso 33:7fedd8029473 153 void draw_people();
evanso 36:27aa597db3d2 154
evanso 36:27aa597db3d2 155 //Map Control
evanso 36:27aa597db3d2 156 /** Resets map after set time so spaceship explosion animation showes */
evanso 36:27aa597db3d2 157 void reset_map_timer();
evanso 33:7fedd8029473 158
evanso 36:27aa597db3d2 159 /** Resets the map after spaceship death and timer has ended */
evanso 36:27aa597db3d2 160 void reset_map();
evanso 36:27aa597db3d2 161
evanso 27:8bb2bd97c319 162 // Variables ---------------------------------------------------------------
evanso 41:5959256f4aab 163
evanso 41:5959256f4aab 164 // Menu Control
evanso 43:d43759dbddb9 165 /** The part of the menu that is currently selected and in*/
evanso 41:5959256f4aab 166 MenuParts current_menu_part_;
evanso 42:3aed75338272 167
evanso 42:3aed75338272 168 /** Volatile flag for ISR */
evanso 45:fc3238cd28c6 169 volatile int lcd_frame_time_flag_;
evanso 56:663d0546c235 170
evanso 56:663d0546c235 171 /** Paused flag */
evanso 56:663d0546c235 172 bool paused_flag_;
evanso 56:663d0546c235 173
evanso 62:f0c86a854a9e 174 /** Flag to exit the play part of the game */
evanso 57:d4ce42c24561 175 bool exit_flag_;
evanso 62:f0c86a854a9e 176
evanso 62:f0c86a854a9e 177 /** Flag to run the save game screen */
evanso 64:e9dfc35a1738 178 bool run_save_a_game_flag_;
evanso 68:bb1650c657ef 179
evanso 68:bb1650c657ef 180 /** Counter for pause screen so pause button doesnt double press */
evanso 68:bb1650c657ef 181 int paused_counter_;
evanso 43:d43759dbddb9 182
evanso 39:fc5586b930e3 183 //Spacehip Control
evanso 39:fc5586b930e3 184 /** Define points*/
evanso 45:fc3238cd28c6 185 int points_;
evanso 18:11068b98e261 186
evanso 27:8bb2bd97c319 187 /** Define direction d of joystick*/
evanso 15:90b6821bcf64 188 Direction d_;
evanso 18:11068b98e261 189
evanso 36:27aa597db3d2 190 /** Flag for if spaceship is destroyed*/
evanso 45:fc3238cd28c6 191 bool spaceship_destroyed_;
evanso 36:27aa597db3d2 192
evanso 30:814674b189f0 193 /** Number of spaceship lives remaining*/
evanso 45:fc3238cd28c6 194 int spaceship_lives_;
evanso 30:814674b189f0 195
evanso 64:e9dfc35a1738 196 // Weapon Control
evanso 64:e9dfc35a1738 197 /** Counter for smart bomb timer*/
evanso 64:e9dfc35a1738 198 int smart_bomb_timer_;
evanso 64:e9dfc35a1738 199
evanso 64:e9dfc35a1738 200 /** Counter for bullet timer*/
evanso 64:e9dfc35a1738 201 int bullet_timer_;
evanso 64:e9dfc35a1738 202
evanso 64:e9dfc35a1738 203 /** Counter for how smart bombs left*/
evanso 64:e9dfc35a1738 204 int smart_bomb_counter_;
evanso 64:e9dfc35a1738 205
evanso 39:fc5586b930e3 206 // Alien Control
evanso 32:c006a9882778 207 /** Counter for spawning aliens*/
evanso 45:fc3238cd28c6 208 int spawn_alien_counter_;
evanso 32:c006a9882778 209
evanso 51:35cb8e604b72 210 /** Numeber of aliens on the screen at a time*/
evanso 51:35cb8e604b72 211 int alien_number_;
evanso 34:85ccc16f24d2 212
evanso 45:fc3238cd28c6 213 /** Miltiplier to increase number of alien as time goes on */
evanso 45:fc3238cd28c6 214 int spawn_time_multipler_;
evanso 64:e9dfc35a1738 215
evanso 64:e9dfc35a1738 216 // Map Control
evanso 64:e9dfc35a1738 217 /** Counter to reset map after set amount of frames*/
evanso 64:e9dfc35a1738 218 int reset_map_counter_;
evanso 64:e9dfc35a1738 219
evanso 27:8bb2bd97c319 220 // Vectors -----------------------------------------------------------------
evanso 27:8bb2bd97c319 221
evanso 27:8bb2bd97c319 222 /** Vector to store each new bullet object*/
evanso 19:1bc0a2d22054 223 std::vector<Weapons> bullet_vector;
evanso 19:1bc0a2d22054 224
evanso 28:a5958497d5ce 225 /** Vector to store each alien bullet object*/
evanso 28:a5958497d5ce 226 std::vector<Weapons> alien_bullet_vector;
evanso 28:a5958497d5ce 227
evanso 27:8bb2bd97c319 228 /** Vector to store each new alien object*/
evanso 20:febd920ec29e 229 std::vector<Alien> alien_vector;
evanso 20:febd920ec29e 230
evanso 27:8bb2bd97c319 231 /** Vector to store each new eplosion object*/
evanso 25:70b55f5bfc87 232 std::vector<Explosion> explosion_vector;
evanso 25:70b55f5bfc87 233
evanso 33:7fedd8029473 234 /** Vector to store each new people object*/
evanso 33:7fedd8029473 235 std::vector<People> people_vector;
evanso 33:7fedd8029473 236
evanso 27:8bb2bd97c319 237 // Objects -----------------------------------------------------------------
evanso 27:8bb2bd97c319 238
evanso 43:d43759dbddb9 239 /** Define Gamepad object */
evanso 13:12276eed13ac 240 Gamepad pad;
evanso 13:12276eed13ac 241
evanso 43:d43759dbddb9 242 /** Define LCD object */
evanso 13:12276eed13ac 243 N5110 lcd;
evanso 13:12276eed13ac 244
evanso 27:8bb2bd97c319 245 /** Define Spaceship object */
evanso 13:12276eed13ac 246 Spaceship spaceship;
evanso 13:12276eed13ac 247
evanso 43:d43759dbddb9 248 /** Define Map object */
evanso 19:1bc0a2d22054 249 Map map;
evanso 33:7fedd8029473 250
evanso 43:d43759dbddb9 251 /** Define Weapons object */
evanso 33:7fedd8029473 252 Weapons weapons;
evanso 39:fc5586b930e3 253
evanso 43:d43759dbddb9 254 /** Define HUD object */
evanso 39:fc5586b930e3 255 HUD hud;
evanso 40:71f947254fda 256
evanso 43:d43759dbddb9 257 /** Define Menu object */
evanso 40:71f947254fda 258 Menu menu;
evanso 42:3aed75338272 259
evanso 69:753ba27325ce 260 /** Define Setting object */
evanso 69:753ba27325ce 261 Settings setting;
evanso 69:753ba27325ce 262
evanso 64:e9dfc35a1738 263 /** Define Ticker object for lcd framerate */
evanso 47:49fa1adc10b4 264 Ticker ticker;
evanso 56:663d0546c235 265
evanso 64:e9dfc35a1738 266 /** Define SavedGames object */
evanso 56:663d0546c235 267 SavedGames saved;
evanso 7:0af4ced868f5 268 };
evanso 7:0af4ced868f5 269
evanso 7:0af4ced868f5 270 #endif