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.
Dependencies: mbed
Diff: Game/Game.cpp
- Revision:
- 29:4a02f0bae202
- Parent:
- 28:f8ff7c8c1627
- Child:
- 30:91038c2afec7
--- a/Game/Game.cpp Thu Apr 04 21:47:00 2019 +0000 +++ b/Game/Game.cpp Thu Apr 04 22:04:10 2019 +0000 @@ -15,11 +15,32 @@ void Game::resetScene(){ for(int i = 0; i < noOfCubes; i++){ //Set initial position of all cubes - cubeArray[i].translate(rand()%250-125,0,10+ i*5); //Position will be based on random integers + cubeArray[i].translate(rand()%250-125, 0, 10+ i*5); //Position will be based on random integers } } +int Game::readHighScore(){ +// filePointer = fopen("/sd/highscore.txt", "r"); + if (filePointer != NULL) { + highScore = fscanf(filePointer, "%i"); + } + else { + highScore = 0; + } + return highScore; + pc.printf("%i", highScore); +} + +void Game::writeHighScore(int score){ + // filePointer = fopen("/sd/highscore.txt", "w"); + if (filePointer != NULL) { + fprintf(filePointer, "%i", score); + } +} + + void Game::run(){ + pc.printf("in"); inHomeMenu = true; score = 0; deathMenuSelection = true; @@ -52,7 +73,7 @@ renderer.drawAllFaces(faceArray, noOfCubes, input.x); //draw all faces added to the face array displayDeathMenu(); //display death menu if cube is too close to user addScore(); - renderer.printScore(score); //print score on top left of screen + renderer.printScore(score, 0, 0); //print score on top left of screen } void Game::checkDespawn(Cube *cube){ //checks if the cube is behind the perspective @@ -76,6 +97,7 @@ } } + void Game::moveCubes(Cube *cube){ //animate cubes if(playing){ if(score < 2000) @@ -89,9 +111,13 @@ } } -void Game::displayDeathMenu(){ //display restart or back to home menu +void Game::displayDeathMenu() { //display restart or back to home menu if(!playing){ - renderer.drawDeathScreen(deathMenuSelection); //draw death screen if game over + if(score > highScore) { + highScore = score; + writeHighScore(highScore); + } + renderer.drawDeathScreen(deathMenuSelection, highScore); //draw death screen if game over deathButtonSelections(); //select menu option } @@ -156,7 +182,6 @@ } void Game::helpScreen(){ - //input.bButton = false; if (help < 2) { renderer.drawHelpScreen1(); checkNextHelpScreen();