Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Thu May 21 22:46:23 2020 +0000
Revision:
68:bb1650c657ef
Parent:
67:a2984682d641
Child:
69:753ba27325ce
Added sprites file to store letter for the title screen and arrows for menus. Also added a time to stop double-button presses.

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