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@33:7fedd8029473, 2020-05-14 (annotated)
- Committer:
- evanso
- Date:
- Thu May 14 22:41:16 2020 +0000
- Revision:
- 33:7fedd8029473
- Parent:
- 32:c006a9882778
- Child:
- 34:85ccc16f24d2
Began work on people class. People now randomly print on screen.
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 | 31:6015e8ed859c | 44 | /** Creats weapons object if button A is pressed and stores in vector */ |
evanso | 31:6015e8ed859c | 45 | void create_weapons(); |
evanso | 19:1bc0a2d22054 | 46 | |
evanso | 27:8bb2bd97c319 | 47 | /** Draws each bullet object and deleted object after set movement |
evanso | 27:8bb2bd97c319 | 48 | * distance |
evanso | 27:8bb2bd97c319 | 49 | */ |
evanso | 19:1bc0a2d22054 | 50 | void draw_bullets(); |
evanso | 13:12276eed13ac | 51 | |
evanso | 22:053c11a202e1 | 52 | /** Creats alien object and stores in vector*/ |
evanso | 20:febd920ec29e | 53 | void create_alien(); |
evanso | 20:febd920ec29e | 54 | |
evanso | 27:8bb2bd97c319 | 55 | /** Draws each alien object and deletes both objects if collision |
evanso | 27:8bb2bd97c319 | 56 | * detected |
evanso | 27:8bb2bd97c319 | 57 | */ |
evanso | 20:febd920ec29e | 58 | void draw_aliens(); |
evanso | 20:febd920ec29e | 59 | |
evanso | 27:8bb2bd97c319 | 60 | /** Creats bullet object if button A is pressed and stores in vector */ |
evanso | 29:e96d91f1d39c | 61 | void create_explosion(Vector2D destroyed_position); |
evanso | 25:70b55f5bfc87 | 62 | |
evanso | 27:8bb2bd97c319 | 63 | /** Draws each explosion object if collision detected */ |
evanso | 25:70b55f5bfc87 | 64 | void draw_explosions(); |
evanso | 25:70b55f5bfc87 | 65 | |
evanso | 30:814674b189f0 | 66 | /** Resets the map after spaceship death*/ |
evanso | 30:814674b189f0 | 67 | void reset_map(); |
evanso | 30:814674b189f0 | 68 | |
evanso | 32:c006a9882778 | 69 | /** Spawns aliens in random position of the screen*/ |
evanso | 32:c006a9882778 | 70 | void spawn_aliens(); |
evanso | 32:c006a9882778 | 71 | |
evanso | 33:7fedd8029473 | 72 | /** Spawns people in random position at bottom of the screen*/ |
evanso | 33:7fedd8029473 | 73 | void create_people(); |
evanso | 33:7fedd8029473 | 74 | |
evanso | 33:7fedd8029473 | 75 | /** Draws each people object */ |
evanso | 33:7fedd8029473 | 76 | void draw_people(); |
evanso | 33:7fedd8029473 | 77 | |
evanso | 27:8bb2bd97c319 | 78 | // Variables --------------------------------------------------------------- |
evanso | 18:11068b98e261 | 79 | |
evanso | 27:8bb2bd97c319 | 80 | /** Define direction d of joystick*/ |
evanso | 15:90b6821bcf64 | 81 | Direction d_; |
evanso | 18:11068b98e261 | 82 | |
evanso | 30:814674b189f0 | 83 | /** Number of spaceship lives remaining*/ |
evanso | 30:814674b189f0 | 84 | int spaceship_lives; |
evanso | 30:814674b189f0 | 85 | |
evanso | 30:814674b189f0 | 86 | /** Flag for if spaceship is destroyed*/ |
evanso | 30:814674b189f0 | 87 | bool spaceship_destroyed; |
evanso | 30:814674b189f0 | 88 | |
evanso | 31:6015e8ed859c | 89 | /** Counter to reset map after set amount of frames*/ |
evanso | 30:814674b189f0 | 90 | int reset_map_counter; |
evanso | 30:814674b189f0 | 91 | |
evanso | 31:6015e8ed859c | 92 | /** Counter for how smart bombs left*/ |
evanso | 31:6015e8ed859c | 93 | int smart_bomb_counter; |
evanso | 31:6015e8ed859c | 94 | |
evanso | 32:c006a9882778 | 95 | /** Counter for spawning aliens*/ |
evanso | 33:7fedd8029473 | 96 | double spawn_alien_rate; |
evanso | 32:c006a9882778 | 97 | |
evanso | 32:c006a9882778 | 98 | /** Counter for spawning aliens*/ |
evanso | 33:7fedd8029473 | 99 | int spawn_alien_counter; |
evanso | 32:c006a9882778 | 100 | |
evanso | 27:8bb2bd97c319 | 101 | // Vectors ----------------------------------------------------------------- |
evanso | 27:8bb2bd97c319 | 102 | |
evanso | 27:8bb2bd97c319 | 103 | /** Vector to store each new bullet object*/ |
evanso | 19:1bc0a2d22054 | 104 | std::vector<Weapons> bullet_vector; |
evanso | 19:1bc0a2d22054 | 105 | |
evanso | 28:a5958497d5ce | 106 | /** Vector to store each alien bullet object*/ |
evanso | 28:a5958497d5ce | 107 | std::vector<Weapons> alien_bullet_vector; |
evanso | 28:a5958497d5ce | 108 | |
evanso | 27:8bb2bd97c319 | 109 | /** Vector to store each new alien object*/ |
evanso | 20:febd920ec29e | 110 | std::vector<Alien> alien_vector; |
evanso | 20:febd920ec29e | 111 | |
evanso | 27:8bb2bd97c319 | 112 | /** Vector to store each new eplosion object*/ |
evanso | 25:70b55f5bfc87 | 113 | std::vector<Explosion> explosion_vector; |
evanso | 25:70b55f5bfc87 | 114 | |
evanso | 33:7fedd8029473 | 115 | /** Vector to store each new people object*/ |
evanso | 33:7fedd8029473 | 116 | std::vector<People> people_vector; |
evanso | 33:7fedd8029473 | 117 | |
evanso | 27:8bb2bd97c319 | 118 | // Objects ----------------------------------------------------------------- |
evanso | 27:8bb2bd97c319 | 119 | |
evanso | 27:8bb2bd97c319 | 120 | /** Define Gamepad object*/ |
evanso | 13:12276eed13ac | 121 | Gamepad pad; |
evanso | 13:12276eed13ac | 122 | |
evanso | 27:8bb2bd97c319 | 123 | /** Define LCD object*/ |
evanso | 13:12276eed13ac | 124 | N5110 lcd; |
evanso | 13:12276eed13ac | 125 | |
evanso | 27:8bb2bd97c319 | 126 | /** Define Spaceship object */ |
evanso | 13:12276eed13ac | 127 | Spaceship spaceship; |
evanso | 13:12276eed13ac | 128 | |
evanso | 27:8bb2bd97c319 | 129 | /** Define Map object*/ |
evanso | 19:1bc0a2d22054 | 130 | Map map; |
evanso | 33:7fedd8029473 | 131 | |
evanso | 33:7fedd8029473 | 132 | /** Define Weapons object*/ |
evanso | 33:7fedd8029473 | 133 | Weapons weapons; |
evanso | 7:0af4ced868f5 | 134 | }; |
evanso | 7:0af4ced868f5 | 135 | |
evanso | 7:0af4ced868f5 | 136 | #endif |