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.
lib/GameEngine/GameEngine.h@34:8dbf401b9906, 2019-05-09 (annotated)
- Committer:
- Kern_EL17KJTF
- Date:
- Thu May 09 10:53:05 2019 +0000
- Revision:
- 34:8dbf401b9906
- Parent:
- 33:3894a7f846a0
- Parent:
- 21:1f44f5493c0d
- Child:
- 39:1d0584a152a6
Publish final test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kern_EL17KJTF | 10:28575a6eaa13 | 1 | #ifndef GAMEENGINE_H |
Kern_EL17KJTF | 10:28575a6eaa13 | 2 | #define GAMEENGINE_H |
Kern_EL17KJTF | 10:28575a6eaa13 | 3 | |
Kern_EL17KJTF | 10:28575a6eaa13 | 4 | #include "mbed.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 5 | #include "N5110.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 6 | #include "Gamepad.h" |
Kern_EL17KJTF | 12:50a7abf21f18 | 7 | #include "Donkey.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 8 | #include "Barrel.h" |
Kern_EL17KJTF | 10:28575a6eaa13 | 9 | #include "Banana.h" |
Kern_EL17KJTF | 33:3894a7f846a0 | 10 | #include "HighScores.h" |
Kern_EL17KJTF | 33:3894a7f846a0 | 11 | #include "Options.h" |
Kern_EL17KJTF | 12:50a7abf21f18 | 12 | |
Kern_EL17KJTF | 21:1f44f5493c0d | 13 | /** GameEngine Class |
Kern_EL17KJTF | 21:1f44f5493c0d | 14 | *@brief This class is running and contrling the main game functions. |
Kern_EL17KJTF | 21:1f44f5493c0d | 15 | *@author Kern Fowler |
Kern_EL17KJTF | 21:1f44f5493c0d | 16 | *@version 1.0 |
Kern_EL17KJTF | 21:1f44f5493c0d | 17 | *@date May 2019 |
Kern_EL17KJTF | 21:1f44f5493c0d | 18 | */ |
Kern_EL17KJTF | 10:28575a6eaa13 | 19 | |
Kern_EL17KJTF | 21:1f44f5493c0d | 20 | class GameEngine { |
Kern_EL17KJTF | 10:28575a6eaa13 | 21 | |
Kern_EL17KJTF | 21:1f44f5493c0d | 22 | public: |
Kern_EL17KJTF | 21:1f44f5493c0d | 23 | /** GameEngine Constructor |
Kern_EL17KJTF | 21:1f44f5493c0d | 24 | @brief Builds my default GameEngine constructor. |
Kern_EL17KJTF | 21:1f44f5493c0d | 25 | @details This does not have any setup. |
Kern_EL17KJTF | 21:1f44f5493c0d | 26 | */ |
Kern_EL17KJTF | 21:1f44f5493c0d | 27 | GameEngine(); |
Kern_EL17KJTF | 21:1f44f5493c0d | 28 | /** GameEngine Destructor |
Kern_EL17KJTF | 21:1f44f5493c0d | 29 | @brief Builds my default GameEngine destructor. |
Kern_EL17KJTF | 21:1f44f5493c0d | 30 | @details This does not have any setup. |
Kern_EL17KJTF | 21:1f44f5493c0d | 31 | */ |
Kern_EL17KJTF | 21:1f44f5493c0d | 32 | ~GameEngine(); |
Kern_EL17KJTF | 21:1f44f5493c0d | 33 | // Mutators |
Kern_EL17KJTF | 10:28575a6eaa13 | 34 | |
Kern_EL17KJTF | 21:1f44f5493c0d | 35 | /** |
Kern_EL17KJTF | 21:1f44f5493c0d | 36 | *@brief Controls the main game. |
Kern_EL17KJTF | 21:1f44f5493c0d | 37 | *@param pad The Gamepad class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 38 | *@param lcd The N5110 class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 39 | *@param barrel The Barrel class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 40 | *@param banana The Banana class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 41 | *@param dky The Donkey class is used. |
Kern_EL17KJTF | 33:3894a7f846a0 | 42 | *@param opt The Options class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 43 | *@details Runs the main functions of the game in correct order. |
Kern_EL17KJTF | 33:3894a7f846a0 | 44 | *@code |
Kern_EL17KJTF | 33:3894a7f846a0 | 45 | void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky, Options &opt) { |
Kern_EL17KJTF | 33:3894a7f846a0 | 46 | wait_ms(250); |
Kern_EL17KJTF | 33:3894a7f846a0 | 47 | // Sets key variables back to default value when game first ran. |
Kern_EL17KJTF | 33:3894a7f846a0 | 48 | barrel_x = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 49 | barrel_y = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 50 | banana_x = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 51 | banana_y = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 52 | running = 1; |
Kern_EL17KJTF | 33:3894a7f846a0 | 53 | banana_time = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 54 | barrel_time = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 55 | score = 0; |
Kern_EL17KJTF | 33:3894a7f846a0 | 56 | while (running == 1) { // Main game loop, continues until game over occurs. |
Kern_EL17KJTF | 33:3894a7f846a0 | 57 | //printf("Game State"); |
Kern_EL17KJTF | 33:3894a7f846a0 | 58 | lcd.clear(); |
Kern_EL17KJTF | 33:3894a7f846a0 | 59 | dky.donkeykong_movement(pad, lcd); // Calls Donkey Kong model section of game. |
Kern_EL17KJTF | 33:3894a7f846a0 | 60 | barrel.barrel_drop(pad, lcd, dky); // Calls Barrel model section of game. |
Kern_EL17KJTF | 33:3894a7f846a0 | 61 | banana.banana_drop(pad, lcd, barrel, dky, opt); // Calls Banana model section of game. |
Kern_EL17KJTF | 33:3894a7f846a0 | 62 | //printf("state %d", running); |
Kern_EL17KJTF | 33:3894a7f846a0 | 63 | lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24. |
Kern_EL17KJTF | 33:3894a7f846a0 | 64 | wait_ms(1.0f/24); |
Kern_EL17KJTF | 33:3894a7f846a0 | 65 | } |
Kern_EL17KJTF | 33:3894a7f846a0 | 66 | } |
Kern_EL17KJTF | 33:3894a7f846a0 | 67 | @endcode |
Kern_EL17KJTF | 21:1f44f5493c0d | 68 | */ |
Kern_EL17KJTF | 33:3894a7f846a0 | 69 | void gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky, Options &opt); |
Kern_EL17KJTF | 21:1f44f5493c0d | 70 | /** |
Kern_EL17KJTF | 21:1f44f5493c0d | 71 | *@brief Shows game over screen. |
Kern_EL17KJTF | 21:1f44f5493c0d | 72 | *@param pad The Gamepad class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 73 | *@param lcd The N5110 class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 74 | *@param banana The Banana class is used. |
Kern_EL17KJTF | 33:3894a7f846a0 | 75 | *@param high The HighScores class is used. |
Kern_EL17KJTF | 21:1f44f5493c0d | 76 | *@details Prints the gameover screen. Prints various text, including total player score. |
Kern_EL17KJTF | 33:3894a7f846a0 | 77 | *@code |
Kern_EL17KJTF | 33:3894a7f846a0 | 78 | void GameEngine::gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana, HighScores &high) { |
Kern_EL17KJTF | 33:3894a7f846a0 | 79 | lcd.clear(); |
Kern_EL17KJTF | 33:3894a7f846a0 | 80 | lcd.printString("Game Over!",14,0); |
Kern_EL17KJTF | 33:3894a7f846a0 | 81 | lcd.printString("Score:",0,2); |
Kern_EL17KJTF | 33:3894a7f846a0 | 82 | char buffer[14]; // Shows final score on screen. |
Kern_EL17KJTF | 33:3894a7f846a0 | 83 | sprintf(buffer,"%i",score); |
Kern_EL17KJTF | 33:3894a7f846a0 | 84 | lcd.printString(buffer,40,2); |
Kern_EL17KJTF | 33:3894a7f846a0 | 85 | high.highscores_new(pad, lcd, banana); // Checks to see if new high score is obtained. |
Kern_EL17KJTF | 33:3894a7f846a0 | 86 | lcd.refresh(); |
Kern_EL17KJTF | 33:3894a7f846a0 | 87 | wait(5); |
Kern_EL17KJTF | 33:3894a7f846a0 | 88 | } |
Kern_EL17KJTF | 33:3894a7f846a0 | 89 | @endcode |
Kern_EL17KJTF | 21:1f44f5493c0d | 90 | */ |
Kern_EL17KJTF | 33:3894a7f846a0 | 91 | void gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana, HighScores &high); |
Kern_EL17KJTF | 10:28575a6eaa13 | 92 | }; |
Kern_EL17KJTF | 10:28575a6eaa13 | 93 | |
Kern_EL17KJTF | 10:28575a6eaa13 | 94 | #endif |