Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GameEngine.cpp Source File

GameEngine.cpp

00001 /*
00002 ELEC2645 Project
00003 GameEngine.cpp
00004 Class file for GameEngine in Donkey Kong game.
00005 */
00006 
00007 #include "GameEngine.h"
00008 
00009 // Constructor - Doesn't require any setup.
00010 GameEngine::GameEngine()
00011 {
00012 
00013 }
00014 
00015 // Deconstructor - Doesn't require any setup.
00016 GameEngine::~GameEngine()
00017 {
00018 
00019 }
00020 
00021 // Runs the main functions of the game in correct order.
00022 void GameEngine::gameengine_run(Gamepad &pad, N5110 &lcd, Barrel &barrel, Banana &banana, Donkey &dky, Options &opt) {
00023     wait_ms(250);
00024     // Sets key variables back to default value when game first ran.
00025     barrel_x = 0; 
00026     barrel_y = 0;
00027     banana_x = 0;
00028     banana_y = 0;
00029     running = 1;
00030     banana_time = 0;
00031     barrel_time = 0;
00032     score = 0;
00033     while (running == 1) { // Main game loop, continues until game over occurs.
00034         //printf("Game State");
00035         lcd.clear();
00036         dky.donkeykong_movement(pad, lcd); // Calls Donkey Kong model section of game.
00037         barrel.barrel_drop(pad, lcd, dky); // Calls Barrel model section of game.
00038         banana.banana_drop(pad, lcd, barrel, dky, opt); // Calls Banana model section of game.
00039         //printf("state %d", running);
00040         lcd.refresh(); // Reloads screen on every cycle, controlled by fps. Default set to 24.
00041         wait_ms(1.0f/24);
00042     }
00043 }
00044 
00045 // Prints the gameover screen. Prints various text, including total player score.
00046 void GameEngine::gameengine_score(Gamepad &pad, N5110 &lcd, Banana &banana, HighScores &high) {
00047     lcd.clear();
00048     lcd.printString("Game Over!",14,0);
00049     lcd.printString("Score:",0,2);
00050     char buffer[14]; // Shows final score on screen.
00051     sprintf(buffer,"%i",score);
00052     lcd.printString(buffer,40,2);
00053     high.highscores_new(pad, lcd, banana); // Checks to see if new high score is obtained.
00054     lcd.refresh();
00055     wait(5);
00056 }