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
Fork of el17ajf by
Diff: Game/Game.cpp
- Revision:
- 28:e09b7ac11dea
- Parent:
- 27:2ed9e3c9f4e9
- Child:
- 29:d59fbe128d1f
--- a/Game/Game.cpp Fri Apr 05 17:16:59 2019 +0000 +++ b/Game/Game.cpp Fri Apr 12 20:53:00 2019 +0000 @@ -1,10 +1,12 @@ #include "Game.h" +#include "Graphics.h" #include "Input.h" #include "Engine.h" #include "MenuManager.h" #include "GameOverMenu.h" #include "PausedMenu.h" #include "Prefs.h" +#include "Math.h" Game::Game(Difficulty difficulty) { currentTetromino = Tetromino::getTetrominoOfType( @@ -73,6 +75,7 @@ void Game::addScore(int rowsCleared) { score += scoreForRow * rowsCleared * rowsCleared; + move_frames = Math::lerp(move_frames, 1, (double)score/9999); if (score > 9999) { score = 9999; } @@ -103,6 +106,7 @@ currentTetromino = currentTetromino.movedDown(); } moveCurrentTetrominoDown(); + Graphics::Game::shake(3); } void Game::draw() { @@ -111,17 +115,23 @@ } void Game::gameOver() { - updateLeaderboard(); printf("Player %i finished game with %i points\n", playerNumber, score); Prefs::getInstance()->setKey(Prefs::LAST_PLAYER, playerNumber); Prefs::getInstance()->setKey(Prefs::LAST_SCORE, score); + Prefs::getInstance()->printAll(); + printf("WRITTEN DATA TO WHATEVER THING\n"); + printf("UPDATING LEADERBOARD\n"); + updateLeaderboard(); + Prefs::getInstance()->printAll(); + printf("DONE UPDATING LEADERBOARD\n"); Menus::MenuManager::add(new Menus::GameOverMenu()); } void Game::updateLeaderboard() { for (int i = 0; i <= Prefs::HIGHSCORE3; i++) { if (score > Prefs::getInstance()->getKey((Prefs::Key)i)) { - for (int j = i; j <= Prefs::HIGHSCORE3; j++) { + // move all scores down + for (int j = Prefs::HIGHSCORE3 - 1; j >= i; j--) { Prefs::getInstance()->setKey( (Prefs::Key)(j + 1), Prefs::getInstance()->getKey((Prefs::Key)i) @@ -131,6 +141,7 @@ Prefs::getInstance()->getKey((Prefs::Key)(i + 3)) ); } + // set ith score to the current score Prefs::getInstance()->setKey((Prefs::Key)i, score); Prefs::getInstance()->setKey((Prefs::Key)(i + 3), playerNumber); break;