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.cpp
- Revision:
- 21:1f44f5493c0d
- Parent:
- 13:94abfe83a294
- Child:
- 31:06713cdbba37
- Child:
- 34:8dbf401b9906
--- a/lib/GameEngine/GameEngine.cpp Wed May 08 23:46:49 2019 +0000 +++ b/lib/GameEngine/GameEngine.cpp Wed May 08 23:47:18 2019 +0000 @@ -6,20 +6,23 @@ #include "GameEngine.h" - +// Constructor - Doesn't require any setup. GameEngine::GameEngine() { } +// Deconstructor - Doesn't require any setup. GameEngine::~GameEngine() { } +// Runs the main functions of the game in correct order. void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky) { wait_ms(250); - barrel_x = 0; + // Sets key variables back to default value when game first ran. + barrel_x = 0; barrel_y = 0; banana_x = 0; banana_y = 0; @@ -27,25 +30,26 @@ banana_time = 0; barrel_time = 0; score = 0; - while (running == 1) { + while (running == 1) { // Main game loop, continues until game over occurs. //printf("Game State"); lcd.clear(); - dky.donkeykong_movement(pad, lcd); - barrel.barrel_drop(pad, lcd, dky); - banana.banana_drop(pad, lcd, barrel, dky); + 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); // Calls Banana model section of game. //printf("state %d", running); - lcd.refresh(); + lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24. wait_ms(1.0f/24); } } +// Prints the gameover screen. Prints various text, including total player score. void GameEngine::gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana) { lcd.clear(); lcd.printString("Game Over!",14,0); lcd.printString("Score:",0,2); - char buffer[14]; + char buffer[14]; // Shows final score on screen. sprintf(buffer,"%i",score); lcd.printString(buffer,40,2); lcd.refresh(); wait(5); -} +} \ No newline at end of file