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