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