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:
- 31:69fedaa9b171
- Parent:
- 29:d59fbe128d1f
- Child:
- 34:0bb0d010e755
--- a/Game/Game.cpp Sat Apr 13 09:29:37 2019 +0000 +++ b/Game/Game.cpp Sat Apr 13 09:53:39 2019 +0000 @@ -9,34 +9,34 @@ #include "Math.h" Game::Game(Difficulty difficulty) { - currentTetromino = Tetromino::getTetrominoOfType( + current_tetromino = Tetromino::getTetrominoOfType( Tetromino::getRandomTetrominoType()); - nextTetrominoType = Tetromino::getRandomTetrominoType(); + next_tetromino_type = Tetromino::getRandomTetrominoType(); switch (difficulty) { case EASY: move_frames = Engine::FPS / 6; // ~ 160ms - scoreForRow = 6; + score_for_row = 6; break; case MEDIUM: move_frames = Engine::FPS / 9; // ~ 110ms - scoreForRow = 8; + score_for_row = 8; break; case HARD: move_frames = Engine::FPS / 12; // ~ 80ms - scoreForRow = 10; + score_for_row = 10; break; } frames = 0; last_move_frame = 0; start_x = Grid::GRID_WIDTH / 2 - 1; - currentTetromino = currentTetromino.teleportedTo(start_x); + current_tetromino = current_tetromino.teleportedTo(start_x); score = 0; - playerNumber = Prefs::getInstance()->getKey(Prefs::LAST_PLAYER); - if (playerNumber == Prefs::EMPTY) { - playerNumber = 1; + player_number = Prefs::getInstance()->getKey(Prefs::LAST_PLAYER); + if (player_number == Prefs::EMPTY) { + player_number = 1; } else { - playerNumber += 1; + player_number += 1; } } @@ -51,18 +51,18 @@ } if (Input::buttonHit(Input::LEFT)) { - if (grid.isSpaceForTetromino(currentTetromino.movedLeft())) { - currentTetromino = currentTetromino.movedLeft(); + if (grid.isSpaceForTetromino(current_tetromino.movedLeft())) { + current_tetromino = current_tetromino.movedLeft(); } } if (Input::buttonHit(Input::RIGHT)) { - if (grid.isSpaceForTetromino(currentTetromino.movedRight())) { - currentTetromino = currentTetromino.movedRight(); + if (grid.isSpaceForTetromino(current_tetromino.movedRight())) { + current_tetromino = current_tetromino.movedRight(); } } if (Input::buttonHit(Input::UP)) { - if (grid.isSpaceForTetromino(currentTetromino.rotatedClockwise())) { - currentTetromino = currentTetromino.rotatedClockwise(); + if (grid.isSpaceForTetromino(current_tetromino.rotatedClockwise())) { + current_tetromino = current_tetromino.rotatedClockwise(); } } if (Input::buttonHit(Input::DOWN)) { @@ -73,8 +73,8 @@ } } -void Game::addScore(int rowsCleared) { - score += scoreForRow * rowsCleared * rowsCleared; +void Game::addScore(int rows_cleared) { + score += score_for_row * rows_cleared * rows_cleared; move_frames = Math::lerp(move_frames, 1, (double)score/9999); if (score > 9999) { score = 9999; @@ -82,40 +82,40 @@ } void Game::moveCurrentTetrominoDown() { - if (grid.isSpaceForTetromino(currentTetromino.movedDown())) { - currentTetromino = currentTetromino.movedDown(); + if (grid.isSpaceForTetromino(current_tetromino.movedDown())) { + current_tetromino = current_tetromino.movedDown(); } else { - int rowsCleared = grid.placeTetromino(currentTetromino); - if (rowsCleared != 0) { - addScore(rowsCleared); + int rows_cleared = grid.placeTetromino(current_tetromino); + if (rows_cleared != 0) { + addScore(rows_cleared); } - currentTetromino = Tetromino::getTetrominoOfType(nextTetrominoType); + current_tetromino = Tetromino::getTetrominoOfType(next_tetromino_type); // centre it - currentTetromino = currentTetromino.teleportedTo(start_x); - if (!grid.isSpaceForTetromino(currentTetromino)) { + current_tetromino = current_tetromino.teleportedTo(start_x); + if (!grid.isSpaceForTetromino(current_tetromino)) { // no space for tetromino, game over gameOver(); } - nextTetrominoType = Tetromino::getRandomTetrominoType(); + next_tetromino_type = Tetromino::getRandomTetrominoType(); } } void Game::dropCurrentTetromino() { - while (grid.isSpaceForTetromino(currentTetromino.movedDown())) { + while (grid.isSpaceForTetromino(current_tetromino.movedDown())) { score += 1; - currentTetromino = currentTetromino.movedDown(); + current_tetromino = current_tetromino.movedDown(); } moveCurrentTetrominoDown(); Graphics::Game::shake(0, 3); } void Game::draw() { - currentTetromino.draw(); + current_tetromino.draw(); grid.draw(); } void Game::gameOver() { - Prefs::getInstance()->setKey(Prefs::LAST_PLAYER, playerNumber); + Prefs::getInstance()->setKey(Prefs::LAST_PLAYER, player_number); Prefs::getInstance()->setKey(Prefs::LAST_SCORE, score); updateLeaderboard(); Menus::MenuManager::add(new Menus::GameOverMenu()); @@ -137,7 +137,7 @@ } // set ith score to the current score Prefs::getInstance()->setKey((Prefs::Key)i, score); - Prefs::getInstance()->setKey((Prefs::Key)(i + 3), playerNumber); + Prefs::getInstance()->setKey((Prefs::Key)(i + 3), player_number); break; } }