Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Committer:
Kern_EL17KJTF
Date:
Thu May 09 10:46:03 2019 +0000
Revision:
33:3894a7f846a0
Parent:
13:94abfe83a294
Child:
34:8dbf401b9906
Mbed update at revision 20 caused an issue when running on board. Downgraded the mbed and now works.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kern_EL17KJTF 10:28575a6eaa13 1 /*
Kern_EL17KJTF 10:28575a6eaa13 2 ELEC2645 Project
Kern_EL17KJTF 10:28575a6eaa13 3 GameEngine.cpp
Kern_EL17KJTF 10:28575a6eaa13 4 Class file for GameEngine in Donkey Kong game.
Kern_EL17KJTF 10:28575a6eaa13 5 */
Kern_EL17KJTF 10:28575a6eaa13 6
Kern_EL17KJTF 10:28575a6eaa13 7 #include "GameEngine.h"
Kern_EL17KJTF 10:28575a6eaa13 8
Kern_EL17KJTF 33:3894a7f846a0 9 // Constructor - Doesn't require any setup.
Kern_EL17KJTF 10:28575a6eaa13 10 GameEngine::GameEngine()
Kern_EL17KJTF 10:28575a6eaa13 11 {
Kern_EL17KJTF 10:28575a6eaa13 12
Kern_EL17KJTF 10:28575a6eaa13 13 }
Kern_EL17KJTF 10:28575a6eaa13 14
Kern_EL17KJTF 33:3894a7f846a0 15 // Deconstructor - Doesn't require any setup.
Kern_EL17KJTF 10:28575a6eaa13 16 GameEngine::~GameEngine()
Kern_EL17KJTF 10:28575a6eaa13 17 {
Kern_EL17KJTF 10:28575a6eaa13 18
Kern_EL17KJTF 10:28575a6eaa13 19 }
Kern_EL17KJTF 10:28575a6eaa13 20
Kern_EL17KJTF 33:3894a7f846a0 21 // Runs the main functions of the game in correct order.
Kern_EL17KJTF 33:3894a7f846a0 22 void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky, Options &opt) {
Kern_EL17KJTF 10:28575a6eaa13 23 wait_ms(250);
Kern_EL17KJTF 33:3894a7f846a0 24 // Sets key variables back to default value when game first ran.
Kern_EL17KJTF 33:3894a7f846a0 25 barrel_x = 0;
Kern_EL17KJTF 12:50a7abf21f18 26 barrel_y = 0;
Kern_EL17KJTF 12:50a7abf21f18 27 banana_x = 0;
Kern_EL17KJTF 12:50a7abf21f18 28 banana_y = 0;
Kern_EL17KJTF 11:b288d01533cc 29 running = 1;
Kern_EL17KJTF 12:50a7abf21f18 30 banana_time = 0;
Kern_EL17KJTF 12:50a7abf21f18 31 barrel_time = 0;
Kern_EL17KJTF 12:50a7abf21f18 32 score = 0;
Kern_EL17KJTF 33:3894a7f846a0 33 while (running == 1) { // Main game loop, continues until game over occurs.
Kern_EL17KJTF 10:28575a6eaa13 34 //printf("Game State");
Kern_EL17KJTF 10:28575a6eaa13 35 lcd.clear();
Kern_EL17KJTF 33:3894a7f846a0 36 dky.donkeykong_movement(pad, lcd); // Calls Donkey Kong model section of game.
Kern_EL17KJTF 33:3894a7f846a0 37 barrel.barrel_drop(pad, lcd, dky); // Calls Barrel model section of game.
Kern_EL17KJTF 33:3894a7f846a0 38 banana.banana_drop(pad, lcd, barrel, dky, opt); // Calls Banana model section of game.
Kern_EL17KJTF 12:50a7abf21f18 39 //printf("state %d", running);
Kern_EL17KJTF 33:3894a7f846a0 40 lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24.
Kern_EL17KJTF 10:28575a6eaa13 41 wait_ms(1.0f/24);
Kern_EL17KJTF 10:28575a6eaa13 42 }
Kern_EL17KJTF 12:50a7abf21f18 43 }
Kern_EL17KJTF 12:50a7abf21f18 44
Kern_EL17KJTF 33:3894a7f846a0 45 // Prints the gameover screen. Prints various text, including total player score.
Kern_EL17KJTF 33:3894a7f846a0 46 void GameEngine::gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana, HighScores &high) {
Kern_EL17KJTF 12:50a7abf21f18 47 lcd.clear();
Kern_EL17KJTF 12:50a7abf21f18 48 lcd.printString("Game Over!",14,0);
Kern_EL17KJTF 12:50a7abf21f18 49 lcd.printString("Score:",0,2);
Kern_EL17KJTF 33:3894a7f846a0 50 char buffer[14]; // Shows final score on screen.
Kern_EL17KJTF 12:50a7abf21f18 51 sprintf(buffer,"%i",score);
Kern_EL17KJTF 12:50a7abf21f18 52 lcd.printString(buffer,40,2);
Kern_EL17KJTF 33:3894a7f846a0 53 high.highscores_new(pad, lcd, banana); // Checks to see if new high score is obtained.
Kern_EL17KJTF 12:50a7abf21f18 54 lcd.refresh();
Kern_EL17KJTF 12:50a7abf21f18 55 wait(5);
Kern_EL17KJTF 33:3894a7f846a0 56 }