Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GameEngine/GameEngine.h@36:27aa597db3d2, 2020-05-15 (annotated)
- Committer:
- evanso
- Date:
- Fri May 15 16:31:25 2020 +0000
- Revision:
- 36:27aa597db3d2
- Parent:
- 34:85ccc16f24d2
- Child:
- 39:fc5586b930e3
Created Parent Classes folder to hold all of the parent class files. Shortened function lengths in Game Engine class and organised function definitions.
Who changed what in which revision?
User | Revision | Line number | New 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 | 32:c006a9882778 | 14 | #include <cmath> |
evanso | 18:11068b98e261 | 15 | #include <vector> |
evanso | 7:0af4ced868f5 | 16 | |
evanso | 11:ab578a151f67 | 17 | /** GameEngine class |
evanso | 27:8bb2bd97c319 | 18 | * @brief Runs the different parts of the game |
evanso | 27:8bb2bd97c319 | 19 | * @author Benjamin Evans, University of Leeds |
evanso | 27:8bb2bd97c319 | 20 | * @date April 2020 |
evanso | 27:8bb2bd97c319 | 21 | */ |
evanso | 7:0af4ced868f5 | 22 | class GameEngine { |
evanso | 7:0af4ced868f5 | 23 | public: |
evanso | 7:0af4ced868f5 | 24 | /** Constructor */ |
evanso | 7:0af4ced868f5 | 25 | GameEngine(); |
evanso | 7:0af4ced868f5 | 26 | |
evanso | 7:0af4ced868f5 | 27 | /** Destructor */ |
evanso | 7:0af4ced868f5 | 28 | ~GameEngine(); |
evanso | 7:0af4ced868f5 | 29 | |
evanso | 14:7419c680656f | 30 | /** Initalises GameEngine */ |
evanso | 13:12276eed13ac | 31 | void init(); |
evanso | 7:0af4ced868f5 | 32 | |
evanso | 14:7419c680656f | 33 | /** Main gameplay loop that runs playable part of game */ |
evanso | 13:12276eed13ac | 34 | void gameplay_loop(); |
evanso | 15:90b6821bcf64 | 35 | |
evanso | 27:8bb2bd97c319 | 36 | // Accessors and mutators -------------------------------------------------- |
evanso | 11:ab578a151f67 | 37 | |
evanso | 11:ab578a151f67 | 38 | private: |
evanso | 27:8bb2bd97c319 | 39 | // Function prototypes ----------------------------------------------------- |
evanso | 18:11068b98e261 | 40 | |
evanso | 27:8bb2bd97c319 | 41 | /** Gets joystick direction from gamepad and stores it in d_ */ |
evanso | 18:11068b98e261 | 42 | void read_joystick_direction(); |
evanso | 11:ab578a151f67 | 43 | |
evanso | 36:27aa597db3d2 | 44 | //Weapon Control |
evanso | 36:27aa597db3d2 | 45 | /** Creates weapons object if button A is pressed and stores in vector */ |
evanso | 36:27aa597db3d2 | 46 | void create_weapons_bullets(); |
evanso | 36:27aa597db3d2 | 47 | |
evanso | 36:27aa597db3d2 | 48 | /** Creates smart bomb if button B is pressed */ |
evanso | 36:27aa597db3d2 | 49 | void create_weapons_smart_bomb(); |
evanso | 19:1bc0a2d22054 | 50 | |
evanso | 27:8bb2bd97c319 | 51 | /** Draws each bullet object and deleted object after set movement |
evanso | 27:8bb2bd97c319 | 52 | * distance |
evanso | 27:8bb2bd97c319 | 53 | */ |
evanso | 19:1bc0a2d22054 | 54 | void draw_bullets(); |
evanso | 13:12276eed13ac | 55 | |
evanso | 36:27aa597db3d2 | 56 | //Alien Control |
evanso | 36:27aa597db3d2 | 57 | /** Spawns aliens in random position of the screen*/ |
evanso | 36:27aa597db3d2 | 58 | void spawn_aliens(); |
evanso | 36:27aa597db3d2 | 59 | |
evanso | 22:053c11a202e1 | 60 | /** Creats alien object and stores in vector*/ |
evanso | 20:febd920ec29e | 61 | void create_alien(); |
evanso | 20:febd920ec29e | 62 | |
evanso | 36:27aa597db3d2 | 63 | /** Checks for alien people collision and sets abduction movements |
evanso | 36:27aa597db3d2 | 64 | * @param i @details iterator from draw_alien for loop |
evanso | 36:27aa597db3d2 | 65 | */ |
evanso | 36:27aa597db3d2 | 66 | void check_alien_people_collision(int i); |
evanso | 36:27aa597db3d2 | 67 | |
evanso | 36:27aa597db3d2 | 68 | /** Gets alien to fire bullets randomley towards spaceship |
evanso | 36:27aa597db3d2 | 69 | * @param i @details iterator from draw_alien for loop |
evanso | 36:27aa597db3d2 | 70 | */ |
evanso | 36:27aa597db3d2 | 71 | void alliens_fire_bullets(int i); |
evanso | 36:27aa597db3d2 | 72 | |
evanso | 36:27aa597db3d2 | 73 | /**Deletes bullet and alien if collision detected and draws explosion |
evanso | 36:27aa597db3d2 | 74 | * @param i @details iterator from draw_alien for loop |
evanso | 36:27aa597db3d2 | 75 | */ |
evanso | 36:27aa597db3d2 | 76 | void delete_aliens(int i); |
evanso | 36:27aa597db3d2 | 77 | |
evanso | 27:8bb2bd97c319 | 78 | /** Draws each alien object and deletes both objects if collision |
evanso | 27:8bb2bd97c319 | 79 | * detected |
evanso | 27:8bb2bd97c319 | 80 | */ |
evanso | 20:febd920ec29e | 81 | void draw_aliens(); |
evanso | 20:febd920ec29e | 82 | |
evanso | 36:27aa597db3d2 | 83 | //Explotion Control |
evanso | 36:27aa597db3d2 | 84 | /** Creates bullet object if button A is pressed and stores in vector */ |
evanso | 29:e96d91f1d39c | 85 | void create_explosion(Vector2D destroyed_position); |
evanso | 25:70b55f5bfc87 | 86 | |
evanso | 27:8bb2bd97c319 | 87 | /** Draws each explosion object if collision detected */ |
evanso | 25:70b55f5bfc87 | 88 | void draw_explosions(); |
evanso | 25:70b55f5bfc87 | 89 | |
evanso | 36:27aa597db3d2 | 90 | //People Control |
evanso | 36:27aa597db3d2 | 91 | /** Spawns people in random places at bottom of screen */ |
evanso | 36:27aa597db3d2 | 92 | void spawn_people(); |
evanso | 32:c006a9882778 | 93 | |
evanso | 33:7fedd8029473 | 94 | /** Spawns people in random position at bottom of the screen*/ |
evanso | 33:7fedd8029473 | 95 | void create_people(); |
evanso | 33:7fedd8029473 | 96 | |
evanso | 33:7fedd8029473 | 97 | /** Draws each people object */ |
evanso | 33:7fedd8029473 | 98 | void draw_people(); |
evanso | 36:27aa597db3d2 | 99 | |
evanso | 36:27aa597db3d2 | 100 | //Map Control |
evanso | 36:27aa597db3d2 | 101 | /** Resets map after set time so spaceship explosion animation showes */ |
evanso | 36:27aa597db3d2 | 102 | void reset_map_timer(); |
evanso | 33:7fedd8029473 | 103 | |
evanso | 36:27aa597db3d2 | 104 | /** Resets the map after spaceship death and timer has ended */ |
evanso | 36:27aa597db3d2 | 105 | void reset_map(); |
evanso | 36:27aa597db3d2 | 106 | |
evanso | 27:8bb2bd97c319 | 107 | // Variables --------------------------------------------------------------- |
evanso | 18:11068b98e261 | 108 | |
evanso | 27:8bb2bd97c319 | 109 | /** Define direction d of joystick*/ |
evanso | 15:90b6821bcf64 | 110 | Direction d_; |
evanso | 18:11068b98e261 | 111 | |
evanso | 36:27aa597db3d2 | 112 | /** Flag for if spaceship is destroyed*/ |
evanso | 36:27aa597db3d2 | 113 | bool spaceship_destroyed; |
evanso | 36:27aa597db3d2 | 114 | |
evanso | 30:814674b189f0 | 115 | /** Number of spaceship lives remaining*/ |
evanso | 30:814674b189f0 | 116 | int spaceship_lives; |
evanso | 30:814674b189f0 | 117 | |
evanso | 31:6015e8ed859c | 118 | /** Counter to reset map after set amount of frames*/ |
evanso | 30:814674b189f0 | 119 | int reset_map_counter; |
evanso | 30:814674b189f0 | 120 | |
evanso | 31:6015e8ed859c | 121 | /** Counter for how smart bombs left*/ |
evanso | 31:6015e8ed859c | 122 | int smart_bomb_counter; |
evanso | 31:6015e8ed859c | 123 | |
evanso | 32:c006a9882778 | 124 | /** Counter for spawning aliens*/ |
evanso | 33:7fedd8029473 | 125 | int spawn_alien_counter; |
evanso | 32:c006a9882778 | 126 | |
evanso | 34:85ccc16f24d2 | 127 | /** Counter for numeber of aliens*/ |
evanso | 34:85ccc16f24d2 | 128 | int alien_number_counter; |
evanso | 34:85ccc16f24d2 | 129 | |
evanso | 36:27aa597db3d2 | 130 | /** Counter for spawning aliens*/ |
evanso | 36:27aa597db3d2 | 131 | double spawn_alien_rate; |
evanso | 36:27aa597db3d2 | 132 | |
evanso | 27:8bb2bd97c319 | 133 | // Vectors ----------------------------------------------------------------- |
evanso | 27:8bb2bd97c319 | 134 | |
evanso | 27:8bb2bd97c319 | 135 | /** Vector to store each new bullet object*/ |
evanso | 19:1bc0a2d22054 | 136 | std::vector<Weapons> bullet_vector; |
evanso | 19:1bc0a2d22054 | 137 | |
evanso | 28:a5958497d5ce | 138 | /** Vector to store each alien bullet object*/ |
evanso | 28:a5958497d5ce | 139 | std::vector<Weapons> alien_bullet_vector; |
evanso | 28:a5958497d5ce | 140 | |
evanso | 27:8bb2bd97c319 | 141 | /** Vector to store each new alien object*/ |
evanso | 20:febd920ec29e | 142 | std::vector<Alien> alien_vector; |
evanso | 20:febd920ec29e | 143 | |
evanso | 27:8bb2bd97c319 | 144 | /** Vector to store each new eplosion object*/ |
evanso | 25:70b55f5bfc87 | 145 | std::vector<Explosion> explosion_vector; |
evanso | 25:70b55f5bfc87 | 146 | |
evanso | 33:7fedd8029473 | 147 | /** Vector to store each new people object*/ |
evanso | 33:7fedd8029473 | 148 | std::vector<People> people_vector; |
evanso | 33:7fedd8029473 | 149 | |
evanso | 27:8bb2bd97c319 | 150 | // Objects ----------------------------------------------------------------- |
evanso | 27:8bb2bd97c319 | 151 | |
evanso | 27:8bb2bd97c319 | 152 | /** Define Gamepad object*/ |
evanso | 13:12276eed13ac | 153 | Gamepad pad; |
evanso | 13:12276eed13ac | 154 | |
evanso | 27:8bb2bd97c319 | 155 | /** Define LCD object*/ |
evanso | 13:12276eed13ac | 156 | N5110 lcd; |
evanso | 13:12276eed13ac | 157 | |
evanso | 27:8bb2bd97c319 | 158 | /** Define Spaceship object */ |
evanso | 13:12276eed13ac | 159 | Spaceship spaceship; |
evanso | 13:12276eed13ac | 160 | |
evanso | 27:8bb2bd97c319 | 161 | /** Define Map object*/ |
evanso | 19:1bc0a2d22054 | 162 | Map map; |
evanso | 33:7fedd8029473 | 163 | |
evanso | 33:7fedd8029473 | 164 | /** Define Weapons object*/ |
evanso | 33:7fedd8029473 | 165 | Weapons weapons; |
evanso | 7:0af4ced868f5 | 166 | }; |
evanso | 7:0af4ced868f5 | 167 | |
evanso | 7:0af4ced868f5 | 168 | #endif |