Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Tue May 19 18:52:54 2020 +0000
Revision:
55:c04568b25617
Parent:
51:35cb8e604b72
Child:
56:663d0546c235
Added draw pause screen function to the game engine class.

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