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.
Dependencies: mbed
EnemySpawner/EnemySpawner.h@6:f06ce4cf068a, 2019-05-08 (annotated)
- Committer:
- adat80
- Date:
- Wed May 08 23:21:32 2019 +0000
- Revision:
- 6:f06ce4cf068a
- Parent:
- 3:97cd7b3d89d0
finished
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adat80 | 1:3916f272663e | 1 | #ifndef ENEMYSPAWNER_H |
adat80 | 1:3916f272663e | 2 | #define ENEMYSPAWNER_H |
adat80 | 1:3916f272663e | 3 | |
adat80 | 1:3916f272663e | 4 | #include "mbed.h" |
adat80 | 1:3916f272663e | 5 | #include "Gamepad.h" |
adat80 | 1:3916f272663e | 6 | #include "Enemy.h" |
adat80 | 1:3916f272663e | 7 | |
adat80 | 1:3916f272663e | 8 | |
adat80 | 6:f06ce4cf068a | 9 | /** EnemySpawner Class |
adat80 | 6:f06ce4cf068a | 10 | @author Adam Jones, University of Leeds |
adat80 | 6:f06ce4cf068a | 11 | @brief Creates and controls the levels of the game |
adat80 | 6:f06ce4cf068a | 12 | @date April 2019 |
adat80 | 6:f06ce4cf068a | 13 | @brief Revision 1.0 |
adat80 | 6:f06ce4cf068a | 14 | |
adat80 | 6:f06ce4cf068a | 15 | @code |
adat80 | 6:f06ce4cf068a | 16 | #include "Enemy.h" |
adat80 | 6:f06ce4cf068a | 17 | #include "mbed.h" |
adat80 | 6:f06ce4cf068a | 18 | #include "Gamepad.h" |
adat80 | 6:f06ce4cf068a | 19 | |
adat80 | 6:f06ce4cf068a | 20 | |
adat80 | 6:f06ce4cf068a | 21 | int main() |
adat80 | 6:f06ce4cf068a | 22 | { |
adat80 | 6:f06ce4cf068a | 23 | //setup pointer to enemy array |
adat80 | 6:f06ce4cf068a | 24 | Enemy *_enemies; |
adat80 | 6:f06ce4cf068a | 25 | //setup level enemy spawner object |
adat80 | 6:f06ce4cf068a | 26 | EnemySpawner _level; |
adat80 | 6:f06ce4cf068a | 27 | |
adat80 | 6:f06ce4cf068a | 28 | |
adat80 | 6:f06ce4cf068a | 29 | //create level and return array of enemies |
adat80 | 6:f06ce4cf068a | 30 | int _levelNumber = 1 //integer level number |
adat80 | 6:f06ce4cf068a | 31 | _enemies = _level.init(_levelNumber); |
adat80 | 6:f06ce4cf068a | 32 | |
adat80 | 6:f06ce4cf068a | 33 | //returns number of enemies in level |
adat80 | 6:f06ce4cf068a | 34 | int numOfEnemies = _level.get_number_of_enemies() |
adat80 | 6:f06ce4cf068a | 35 | |
adat80 | 6:f06ce4cf068a | 36 | //updates level |
adat80 | 6:f06ce4cf068a | 37 | _level.update(_fps); |
adat80 | 6:f06ce4cf068a | 38 | } |
adat80 | 6:f06ce4cf068a | 39 | |
adat80 | 6:f06ce4cf068a | 40 | @endcode |
adat80 | 6:f06ce4cf068a | 41 | |
adat80 | 6:f06ce4cf068a | 42 | |
adat80 | 6:f06ce4cf068a | 43 | */ |
adat80 | 6:f06ce4cf068a | 44 | |
adat80 | 6:f06ce4cf068a | 45 | |
adat80 | 1:3916f272663e | 46 | class EnemySpawner |
adat80 | 1:3916f272663e | 47 | { |
adat80 | 1:3916f272663e | 48 | |
adat80 | 1:3916f272663e | 49 | public: |
adat80 | 1:3916f272663e | 50 | EnemySpawner(); |
adat80 | 1:3916f272663e | 51 | ~EnemySpawner(); |
adat80 | 1:3916f272663e | 52 | |
adat80 | 6:f06ce4cf068a | 53 | /** |
adat80 | 6:f06ce4cf068a | 54 | * @brief Initialises the game level |
adat80 | 6:f06ce4cf068a | 55 | * @param level @details the number of the level of the game |
adat80 | 6:f06ce4cf068a | 56 | * @returns Enemy* @details a pointer to an array of enemy objects |
adat80 | 6:f06ce4cf068a | 57 | */ |
adat80 | 1:3916f272663e | 58 | Enemy* init(int level); |
adat80 | 6:f06ce4cf068a | 59 | |
adat80 | 6:f06ce4cf068a | 60 | /** |
adat80 | 6:f06ce4cf068a | 61 | * @brief Updates to keep track of the time and tell indicidual enemies when to begin moving |
adat80 | 6:f06ce4cf068a | 62 | * @param fps @details the fps of the game |
adat80 | 6:f06ce4cf068a | 63 | */ |
adat80 | 1:3916f272663e | 64 | void update(int fps); |
adat80 | 1:3916f272663e | 65 | |
adat80 | 6:f06ce4cf068a | 66 | /** |
adat80 | 6:f06ce4cf068a | 67 | * @brief Gets the number of enemies in level |
adat80 | 6:f06ce4cf068a | 68 | * @returns number of enemies @details an integer value of the number of enemies in the level |
adat80 | 6:f06ce4cf068a | 69 | */ |
adat80 | 3:97cd7b3d89d0 | 70 | int get_number_of_enemies(); |
adat80 | 3:97cd7b3d89d0 | 71 | |
adat80 | 1:3916f272663e | 72 | private: |
adat80 | 1:3916f272663e | 73 | float _minTimeBetweenSpawns; |
adat80 | 1:3916f272663e | 74 | float _timeIntoLevel; |
adat80 | 3:97cd7b3d89d0 | 75 | int _number_of_enemies; |
adat80 | 1:3916f272663e | 76 | Enemy *_enemies; |
adat80 | 1:3916f272663e | 77 | int _level; |
adat80 | 1:3916f272663e | 78 | }; |
adat80 | 1:3916f272663e | 79 | |
adat80 | 1:3916f272663e | 80 | #endif |