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:
- 15:afeefa3ceb61
- Parent:
- 13:59e17cab320a
- Child:
- 17:cc448ab7266f
--- a/Game/Game.cpp Mon Mar 18 18:26:11 2019 +0000 +++ b/Game/Game.cpp Tue Mar 19 10:36:51 2019 +0000 @@ -2,10 +2,22 @@ #include "Input.h" #include "mbed.h" // TODO +/* BUGS: + * + * SWITCH BOUNCE + * NO DOUBLE ROW CLEAR + * + */ + Game::Game() { currentTetromino = Tetromino::getTetrominoOfType( Tetromino::getRandomTetrominoType()); nextTetrominoType = Tetromino::getRandomTetrominoType(); + move_frames = 3; + frames = 0; + last_move_frame = 0; + start_x = Grid::GRID_WIDTH / 2 - 1; + currentTetromino = currentTetromino.teleportedTo(start_x); } Game::~Game() { @@ -13,6 +25,11 @@ } void Game::update() { + if (frames++ > last_move_frame + move_frames) { + last_move_frame = frames; + moveCurrentTetrominoDown(); + } + if (Input::buttonHit(Input::LEFT)) { if (grid.isSpaceForTetromino(currentTetromino.movedLeft())) { currentTetromino = currentTetromino.movedLeft(); @@ -41,6 +58,12 @@ } else { grid.placeTetromino(currentTetromino); currentTetromino = Tetromino::getTetrominoOfType(nextTetrominoType); + // centre it + currentTetromino = currentTetromino.teleportedTo(start_x); + if (!grid.isSpaceForTetromino(currentTetromino)) { + // no space for tetromino, game over + gameOver(); + } nextTetrominoType = Tetromino::getRandomTetrominoType(); } } @@ -56,3 +79,7 @@ currentTetromino.draw(); grid.draw(); } + +void Game::gameOver() { + // TODO +}