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@32:c006a9882778, 2020-05-14 (annotated)
- Committer:
- evanso
- Date:
- Thu May 14 20:04:14 2020 +0000
- Revision:
- 32:c006a9882778
- Parent:
- 31:6015e8ed859c
- Child:
- 33:7fedd8029473
Multiple aliens now spawn in random positions and game has a set spawn rate.
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 | 32:c006a9882778 | 13 | #include <cmath> |
evanso | 18:11068b98e261 | 14 | #include <vector> |
evanso | 7:0af4ced868f5 | 15 | |
evanso | 11:ab578a151f67 | 16 | /** GameEngine class |
evanso | 27:8bb2bd97c319 | 17 | * @brief Runs the different parts of the game |
evanso | 27:8bb2bd97c319 | 18 | * @author Benjamin Evans, University of Leeds |
evanso | 27:8bb2bd97c319 | 19 | * @date April 2020 |
evanso | 27:8bb2bd97c319 | 20 | */ |
evanso | 7:0af4ced868f5 | 21 | class GameEngine { |
evanso | 7:0af4ced868f5 | 22 | public: |
evanso | 7:0af4ced868f5 | 23 | /** Constructor */ |
evanso | 7:0af4ced868f5 | 24 | GameEngine(); |
evanso | 7:0af4ced868f5 | 25 | |
evanso | 7:0af4ced868f5 | 26 | /** Destructor */ |
evanso | 7:0af4ced868f5 | 27 | ~GameEngine(); |
evanso | 7:0af4ced868f5 | 28 | |
evanso | 14:7419c680656f | 29 | /** Initalises GameEngine */ |
evanso | 13:12276eed13ac | 30 | void init(); |
evanso | 7:0af4ced868f5 | 31 | |
evanso | 14:7419c680656f | 32 | /** Main gameplay loop that runs playable part of game */ |
evanso | 13:12276eed13ac | 33 | void gameplay_loop(); |
evanso | 15:90b6821bcf64 | 34 | |
evanso | 27:8bb2bd97c319 | 35 | // Accessors and mutators -------------------------------------------------- |
evanso | 11:ab578a151f67 | 36 | |
evanso | 11:ab578a151f67 | 37 | private: |
evanso | 27:8bb2bd97c319 | 38 | // Function prototypes ----------------------------------------------------- |
evanso | 18:11068b98e261 | 39 | |
evanso | 27:8bb2bd97c319 | 40 | /** Gets joystick direction from gamepad and stores it in d_ */ |
evanso | 18:11068b98e261 | 41 | void read_joystick_direction(); |
evanso | 11:ab578a151f67 | 42 | |
evanso | 31:6015e8ed859c | 43 | /** Creats weapons object if button A is pressed and stores in vector */ |
evanso | 31:6015e8ed859c | 44 | void create_weapons(); |
evanso | 19:1bc0a2d22054 | 45 | |
evanso | 27:8bb2bd97c319 | 46 | /** Draws each bullet object and deleted object after set movement |
evanso | 27:8bb2bd97c319 | 47 | * distance |
evanso | 27:8bb2bd97c319 | 48 | */ |
evanso | 19:1bc0a2d22054 | 49 | void draw_bullets(); |
evanso | 13:12276eed13ac | 50 | |
evanso | 22:053c11a202e1 | 51 | /** Creats alien object and stores in vector*/ |
evanso | 20:febd920ec29e | 52 | void create_alien(); |
evanso | 20:febd920ec29e | 53 | |
evanso | 27:8bb2bd97c319 | 54 | /** Draws each alien object and deletes both objects if collision |
evanso | 27:8bb2bd97c319 | 55 | * detected |
evanso | 27:8bb2bd97c319 | 56 | */ |
evanso | 20:febd920ec29e | 57 | void draw_aliens(); |
evanso | 20:febd920ec29e | 58 | |
evanso | 27:8bb2bd97c319 | 59 | /** Creats bullet object if button A is pressed and stores in vector */ |
evanso | 29:e96d91f1d39c | 60 | void create_explosion(Vector2D destroyed_position); |
evanso | 25:70b55f5bfc87 | 61 | |
evanso | 27:8bb2bd97c319 | 62 | /** Draws each explosion object if collision detected */ |
evanso | 25:70b55f5bfc87 | 63 | void draw_explosions(); |
evanso | 25:70b55f5bfc87 | 64 | |
evanso | 30:814674b189f0 | 65 | /** Resets the map after spaceship death*/ |
evanso | 30:814674b189f0 | 66 | void reset_map(); |
evanso | 30:814674b189f0 | 67 | |
evanso | 32:c006a9882778 | 68 | /** Spawns aliens in random position of the screen*/ |
evanso | 32:c006a9882778 | 69 | void spawn_aliens(); |
evanso | 32:c006a9882778 | 70 | |
evanso | 27:8bb2bd97c319 | 71 | // Variables --------------------------------------------------------------- |
evanso | 18:11068b98e261 | 72 | |
evanso | 27:8bb2bd97c319 | 73 | /** Define direction d of joystick*/ |
evanso | 15:90b6821bcf64 | 74 | Direction d_; |
evanso | 18:11068b98e261 | 75 | |
evanso | 30:814674b189f0 | 76 | /** Number of spaceship lives remaining*/ |
evanso | 30:814674b189f0 | 77 | int spaceship_lives; |
evanso | 30:814674b189f0 | 78 | |
evanso | 30:814674b189f0 | 79 | /** Flag for if spaceship is destroyed*/ |
evanso | 30:814674b189f0 | 80 | bool spaceship_destroyed; |
evanso | 30:814674b189f0 | 81 | |
evanso | 31:6015e8ed859c | 82 | /** Counter to reset map after set amount of frames*/ |
evanso | 30:814674b189f0 | 83 | int reset_map_counter; |
evanso | 30:814674b189f0 | 84 | |
evanso | 31:6015e8ed859c | 85 | /** Counter for how smart bombs left*/ |
evanso | 31:6015e8ed859c | 86 | int smart_bomb_counter; |
evanso | 31:6015e8ed859c | 87 | |
evanso | 32:c006a9882778 | 88 | /** Counter for spawning aliens*/ |
evanso | 32:c006a9882778 | 89 | double spawn_alien_counter; |
evanso | 32:c006a9882778 | 90 | |
evanso | 32:c006a9882778 | 91 | /** Counter for spawning aliens*/ |
evanso | 32:c006a9882778 | 92 | int spawn_alien_counter_two; |
evanso | 32:c006a9882778 | 93 | |
evanso | 27:8bb2bd97c319 | 94 | // Vectors ----------------------------------------------------------------- |
evanso | 27:8bb2bd97c319 | 95 | |
evanso | 27:8bb2bd97c319 | 96 | /** Vector to store each new bullet object*/ |
evanso | 19:1bc0a2d22054 | 97 | std::vector<Weapons> bullet_vector; |
evanso | 19:1bc0a2d22054 | 98 | |
evanso | 28:a5958497d5ce | 99 | /** Vector to store each alien bullet object*/ |
evanso | 28:a5958497d5ce | 100 | std::vector<Weapons> alien_bullet_vector; |
evanso | 28:a5958497d5ce | 101 | |
evanso | 27:8bb2bd97c319 | 102 | /** Vector to store each new alien object*/ |
evanso | 20:febd920ec29e | 103 | std::vector<Alien> alien_vector; |
evanso | 20:febd920ec29e | 104 | |
evanso | 27:8bb2bd97c319 | 105 | /** Vector to store each new eplosion object*/ |
evanso | 25:70b55f5bfc87 | 106 | std::vector<Explosion> explosion_vector; |
evanso | 25:70b55f5bfc87 | 107 | |
evanso | 27:8bb2bd97c319 | 108 | // Objects ----------------------------------------------------------------- |
evanso | 27:8bb2bd97c319 | 109 | |
evanso | 27:8bb2bd97c319 | 110 | /** Define Gamepad object*/ |
evanso | 13:12276eed13ac | 111 | Gamepad pad; |
evanso | 13:12276eed13ac | 112 | |
evanso | 27:8bb2bd97c319 | 113 | /** Define LCD object*/ |
evanso | 13:12276eed13ac | 114 | N5110 lcd; |
evanso | 13:12276eed13ac | 115 | |
evanso | 27:8bb2bd97c319 | 116 | /** Define Spaceship object */ |
evanso | 13:12276eed13ac | 117 | Spaceship spaceship; |
evanso | 13:12276eed13ac | 118 | |
evanso | 27:8bb2bd97c319 | 119 | /** Define Map object*/ |
evanso | 19:1bc0a2d22054 | 120 | Map map; |
evanso | 7:0af4ced868f5 | 121 | }; |
evanso | 7:0af4ced868f5 | 122 | |
evanso | 7:0af4ced868f5 | 123 | #endif |