Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Tue May 19 19:58:49 2020 +0000
Revision:
57:d4ce42c24561
Parent:
56:663d0546c235
Child:
58:a9a39424df52
Added draw game over screen function to GameEngine

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