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.
Diff: lib/GameEngine/GameEngine.h
- Revision:
- 33:3894a7f846a0
- Parent:
- 12:50a7abf21f18
- Child:
- 34:8dbf401b9906
--- a/lib/GameEngine/GameEngine.h Wed May 08 23:46:49 2019 +0000 +++ b/lib/GameEngine/GameEngine.h Thu May 09 10:46:03 2019 +0000 @@ -1,10 +1,5 @@ #ifndef GAMEENGINE_H #define GAMEENGINE_H -/* -ELEC2645 Project -GameEngine.h -Class file for GameEngine in Donkey Kong game. -*/ #include "mbed.h" #include "N5110.h" @@ -12,20 +7,88 @@ #include "Donkey.h" #include "Barrel.h" #include "Banana.h" +#include "HighScores.h" +#include "Options.h" +/** GameEngine Class +*@brief This class is running and contrling the main game functions. +*@author Kern Fowler +*@version 1.0 +*@date May 2019 +*/ +class GameEngine { -class GameEngine -{ +public: +/** GameEngine Constructor +@brief Builds my default GameEngine constructor. +@details This does not have any setup. +*/ +GameEngine(); +/** GameEngine Destructor +@brief Builds my default GameEngine destructor. +@details This does not have any setup. +*/ +~GameEngine(); +// Mutators - public: - - GameEngine(); - - ~GameEngine(); - - void gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky); - void gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana); +/** +*@brief Controls the main game. +*@param pad The Gamepad class is used. +*@param lcd The N5110 class is used. +*@param barrel The Barrel class is used. +*@param banana The Banana class is used. +*@param dky The Donkey class is used. +*@param opt The Options class is used. +*@details Runs the main functions of the game in correct order. +*@code +void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky, Options &opt) { + wait_ms(250); + // Sets key variables back to default value when game first ran. + barrel_x = 0; + barrel_y = 0; + banana_x = 0; + banana_y = 0; + running = 1; + banana_time = 0; + barrel_time = 0; + score = 0; + while (running == 1) { // Main game loop, continues until game over occurs. + //printf("Game State"); + lcd.clear(); + dky.donkeykong_movement(pad, lcd); // Calls Donkey Kong model section of game. + barrel.barrel_drop(pad, lcd, dky); // Calls Barrel model section of game. + banana.banana_drop(pad, lcd, barrel, dky, opt); // Calls Banana model section of game. + //printf("state %d", running); + lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24. + wait_ms(1.0f/24); + } +} +@endcode +*/ +void gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky, Options &opt); +/** +*@brief Shows game over screen. +*@param pad The Gamepad class is used. +*@param lcd The N5110 class is used. +*@param banana The Banana class is used. +*@param high The HighScores class is used. +*@details Prints the gameover screen. Prints various text, including total player score. +*@code +void GameEngine::gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana, HighScores &high) { + lcd.clear(); + lcd.printString("Game Over!",14,0); + lcd.printString("Score:",0,2); + char buffer[14]; // Shows final score on screen. + sprintf(buffer,"%i",score); + lcd.printString(buffer,40,2); + high.highscores_new(pad, lcd, banana); // Checks to see if new high score is obtained. + lcd.refresh(); + wait(5); +} +@endcode +*/ +void gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana, HighScores &high); }; #endif \ No newline at end of file