Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Sat May 16 21:08:54 2020 +0000
Revision:
39:fc5586b930e3
Parent:
36:27aa597db3d2
Child:
40:71f947254fda
Added HUD (heads up display) class wich displays point, lives and smart bombed lefts. The amount of lives also interacts with LED's through a function in 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 32:c006a9882778 15 #include <cmath>
evanso 18:11068b98e261 16 #include <vector>
evanso 7:0af4ced868f5 17
evanso 11:ab578a151f67 18 /** GameEngine class
evanso 27:8bb2bd97c319 19 * @brief Runs the different parts of the game
evanso 27:8bb2bd97c319 20 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 21 * @date April 2020
evanso 27:8bb2bd97c319 22 */
evanso 7:0af4ced868f5 23 class GameEngine {
evanso 7:0af4ced868f5 24 public:
evanso 7:0af4ced868f5 25 /** Constructor */
evanso 7:0af4ced868f5 26 GameEngine();
evanso 7:0af4ced868f5 27
evanso 7:0af4ced868f5 28 /** Destructor */
evanso 7:0af4ced868f5 29 ~GameEngine();
evanso 7:0af4ced868f5 30
evanso 14:7419c680656f 31 /** Initalises GameEngine */
evanso 13:12276eed13ac 32 void init();
evanso 7:0af4ced868f5 33
evanso 14:7419c680656f 34 /** Main gameplay loop that runs playable part of game */
evanso 13:12276eed13ac 35 void gameplay_loop();
evanso 15:90b6821bcf64 36
evanso 27:8bb2bd97c319 37 // Accessors and mutators --------------------------------------------------
evanso 11:ab578a151f67 38
evanso 11:ab578a151f67 39 private:
evanso 27:8bb2bd97c319 40 // Function prototypes -----------------------------------------------------
evanso 39:fc5586b930e3 41
evanso 39:fc5586b930e3 42 //Spaceship Control
evanso 27:8bb2bd97c319 43 /** Gets joystick direction from gamepad and stores it in d_ */
evanso 18:11068b98e261 44 void read_joystick_direction();
evanso 11:ab578a151f67 45
evanso 39:fc5586b930e3 46 /** Turns on specific leds depending on how many lives left */
evanso 39:fc5586b930e3 47 void spaceship_lives_leds();
evanso 39:fc5586b930e3 48
evanso 36:27aa597db3d2 49 //Weapon Control
evanso 39:fc5586b930e3 50 /** Creates weapons object if button A is pressed and stores in vector*/
evanso 36:27aa597db3d2 51 void create_weapons_bullets();
evanso 36:27aa597db3d2 52
evanso 36:27aa597db3d2 53 /** Creates smart bomb if button B is pressed */
evanso 36:27aa597db3d2 54 void create_weapons_smart_bomb();
evanso 19:1bc0a2d22054 55
evanso 27:8bb2bd97c319 56 /** Draws each bullet object and deleted object after set movement
evanso 27:8bb2bd97c319 57 * distance
evanso 27:8bb2bd97c319 58 */
evanso 19:1bc0a2d22054 59 void draw_bullets();
evanso 13:12276eed13ac 60
evanso 36:27aa597db3d2 61 //Alien Control
evanso 36:27aa597db3d2 62 /** Spawns aliens in random position of the screen*/
evanso 36:27aa597db3d2 63 void spawn_aliens();
evanso 36:27aa597db3d2 64
evanso 22:053c11a202e1 65 /** Creats alien object and stores in vector*/
evanso 20:febd920ec29e 66 void create_alien();
evanso 20:febd920ec29e 67
evanso 36:27aa597db3d2 68 /** Checks for alien people collision and sets abduction movements
evanso 36:27aa597db3d2 69 * @param i @details iterator from draw_alien for loop
evanso 36:27aa597db3d2 70 */
evanso 36:27aa597db3d2 71 void check_alien_people_collision(int i);
evanso 36:27aa597db3d2 72
evanso 36:27aa597db3d2 73 /** Gets alien to fire bullets randomley towards spaceship
evanso 36:27aa597db3d2 74 * @param i @details iterator from draw_alien for loop
evanso 36:27aa597db3d2 75 */
evanso 36:27aa597db3d2 76 void alliens_fire_bullets(int i);
evanso 36:27aa597db3d2 77
evanso 36:27aa597db3d2 78 /**Deletes bullet and alien if collision detected and draws explosion
evanso 36:27aa597db3d2 79 * @param i @details iterator from draw_alien for loop
evanso 36:27aa597db3d2 80 */
evanso 36:27aa597db3d2 81 void delete_aliens(int i);
evanso 36:27aa597db3d2 82
evanso 27:8bb2bd97c319 83 /** Draws each alien object and deletes both objects if collision
evanso 27:8bb2bd97c319 84 * detected
evanso 27:8bb2bd97c319 85 */
evanso 20:febd920ec29e 86 void draw_aliens();
evanso 20:febd920ec29e 87
evanso 36:27aa597db3d2 88 //Explotion Control
evanso 36:27aa597db3d2 89 /** Creates bullet object if button A is pressed and stores in vector */
evanso 29:e96d91f1d39c 90 void create_explosion(Vector2D destroyed_position);
evanso 25:70b55f5bfc87 91
evanso 27:8bb2bd97c319 92 /** Draws each explosion object if collision detected */
evanso 25:70b55f5bfc87 93 void draw_explosions();
evanso 25:70b55f5bfc87 94
evanso 36:27aa597db3d2 95 //People Control
evanso 36:27aa597db3d2 96 /** Spawns people in random places at bottom of screen */
evanso 36:27aa597db3d2 97 void spawn_people();
evanso 32:c006a9882778 98
evanso 33:7fedd8029473 99 /** Spawns people in random position at bottom of the screen*/
evanso 33:7fedd8029473 100 void create_people();
evanso 33:7fedd8029473 101
evanso 33:7fedd8029473 102 /** Draws each people object */
evanso 33:7fedd8029473 103 void draw_people();
evanso 36:27aa597db3d2 104
evanso 36:27aa597db3d2 105 //Map Control
evanso 36:27aa597db3d2 106 /** Resets map after set time so spaceship explosion animation showes */
evanso 36:27aa597db3d2 107 void reset_map_timer();
evanso 33:7fedd8029473 108
evanso 36:27aa597db3d2 109 /** Resets the map after spaceship death and timer has ended */
evanso 36:27aa597db3d2 110 void reset_map();
evanso 36:27aa597db3d2 111
evanso 27:8bb2bd97c319 112 // Variables ---------------------------------------------------------------
evanso 39:fc5586b930e3 113
evanso 39:fc5586b930e3 114 //Spacehip Control
evanso 39:fc5586b930e3 115 /** Define points*/
evanso 39:fc5586b930e3 116 int points;
evanso 18:11068b98e261 117
evanso 27:8bb2bd97c319 118 /** Define direction d of joystick*/
evanso 15:90b6821bcf64 119 Direction d_;
evanso 18:11068b98e261 120
evanso 36:27aa597db3d2 121 /** Flag for if spaceship is destroyed*/
evanso 36:27aa597db3d2 122 bool spaceship_destroyed;
evanso 36:27aa597db3d2 123
evanso 30:814674b189f0 124 /** Number of spaceship lives remaining*/
evanso 30:814674b189f0 125 int spaceship_lives;
evanso 30:814674b189f0 126
evanso 39:fc5586b930e3 127 // Map Control
evanso 31:6015e8ed859c 128 /** Counter to reset map after set amount of frames*/
evanso 30:814674b189f0 129 int reset_map_counter;
evanso 39:fc5586b930e3 130
evanso 39:fc5586b930e3 131 // Alien Control
evanso 32:c006a9882778 132 /** Counter for spawning aliens*/
evanso 33:7fedd8029473 133 int spawn_alien_counter;
evanso 32:c006a9882778 134
evanso 34:85ccc16f24d2 135 /** Counter for numeber of aliens*/
evanso 34:85ccc16f24d2 136 int alien_number_counter;
evanso 34:85ccc16f24d2 137
evanso 36:27aa597db3d2 138 /** Counter for spawning aliens*/
evanso 36:27aa597db3d2 139 double spawn_alien_rate;
evanso 39:fc5586b930e3 140
evanso 39:fc5586b930e3 141 // Weapon Control
evanso 39:fc5586b930e3 142 /** Counter for smart bomb timer*/
evanso 39:fc5586b930e3 143 int smart_bomb_timer;
evanso 39:fc5586b930e3 144
evanso 39:fc5586b930e3 145 /** Counter for bullet timer*/
evanso 39:fc5586b930e3 146 int bullet_timer;
evanso 39:fc5586b930e3 147
evanso 39:fc5586b930e3 148 /** Counter for how smart bombs left*/
evanso 39:fc5586b930e3 149 int smart_bomb_counter;
evanso 36:27aa597db3d2 150
evanso 27:8bb2bd97c319 151 // Vectors -----------------------------------------------------------------
evanso 27:8bb2bd97c319 152
evanso 27:8bb2bd97c319 153 /** Vector to store each new bullet object*/
evanso 19:1bc0a2d22054 154 std::vector<Weapons> bullet_vector;
evanso 19:1bc0a2d22054 155
evanso 28:a5958497d5ce 156 /** Vector to store each alien bullet object*/
evanso 28:a5958497d5ce 157 std::vector<Weapons> alien_bullet_vector;
evanso 28:a5958497d5ce 158
evanso 27:8bb2bd97c319 159 /** Vector to store each new alien object*/
evanso 20:febd920ec29e 160 std::vector<Alien> alien_vector;
evanso 20:febd920ec29e 161
evanso 27:8bb2bd97c319 162 /** Vector to store each new eplosion object*/
evanso 25:70b55f5bfc87 163 std::vector<Explosion> explosion_vector;
evanso 25:70b55f5bfc87 164
evanso 33:7fedd8029473 165 /** Vector to store each new people object*/
evanso 33:7fedd8029473 166 std::vector<People> people_vector;
evanso 33:7fedd8029473 167
evanso 27:8bb2bd97c319 168 // Objects -----------------------------------------------------------------
evanso 27:8bb2bd97c319 169
evanso 27:8bb2bd97c319 170 /** Define Gamepad object*/
evanso 13:12276eed13ac 171 Gamepad pad;
evanso 13:12276eed13ac 172
evanso 27:8bb2bd97c319 173 /** Define LCD object*/
evanso 13:12276eed13ac 174 N5110 lcd;
evanso 13:12276eed13ac 175
evanso 27:8bb2bd97c319 176 /** Define Spaceship object */
evanso 13:12276eed13ac 177 Spaceship spaceship;
evanso 13:12276eed13ac 178
evanso 27:8bb2bd97c319 179 /** Define Map object*/
evanso 19:1bc0a2d22054 180 Map map;
evanso 33:7fedd8029473 181
evanso 33:7fedd8029473 182 /** Define Weapons object*/
evanso 33:7fedd8029473 183 Weapons weapons;
evanso 39:fc5586b930e3 184
evanso 39:fc5586b930e3 185 /** Define HUD object*/
evanso 39:fc5586b930e3 186 HUD hud;
evanso 7:0af4ced868f5 187 };
evanso 7:0af4ced868f5 188
evanso 7:0af4ced868f5 189 #endif