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