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
Game/Game.cpp@13:59e17cab320a, 2019-03-18 (annotated)
- Committer:
- el17ajf
- Date:
- Mon Mar 18 18:09:57 2019 +0000
- Revision:
- 13:59e17cab320a
- Parent:
- 11:fba7d54fd36b
- Child:
- 15:afeefa3ceb61
got tetrominos dropping and moving!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17ajf | 4:aa433f9865a6 | 1 | #include "Game.h" |
el17ajf | 6:a54df561f442 | 2 | #include "Input.h" |
el17ajf | 13:59e17cab320a | 3 | #include "mbed.h" // TODO |
el17ajf | 2:0b5e289ef905 | 4 | |
el17ajf | 2:0b5e289ef905 | 5 | Game::Game() { |
el17ajf | 7:2e37bad816cb | 6 | currentTetromino = Tetromino::getTetrominoOfType( |
el17ajf | 7:2e37bad816cb | 7 | Tetromino::getRandomTetrominoType()); |
el17ajf | 7:2e37bad816cb | 8 | nextTetrominoType = Tetromino::getRandomTetrominoType(); |
el17ajf | 2:0b5e289ef905 | 9 | } |
el17ajf | 2:0b5e289ef905 | 10 | |
el17ajf | 2:0b5e289ef905 | 11 | Game::~Game() { |
el17ajf | 6:a54df561f442 | 12 | |
el17ajf | 2:0b5e289ef905 | 13 | } |
el17ajf | 2:0b5e289ef905 | 14 | |
el17ajf | 2:0b5e289ef905 | 15 | void Game::update() { |
el17ajf | 9:3a7776a29a11 | 16 | if (Input::buttonHit(Input::LEFT)) { |
el17ajf | 7:2e37bad816cb | 17 | if (grid.isSpaceForTetromino(currentTetromino.movedLeft())) { |
el17ajf | 4:aa433f9865a6 | 18 | currentTetromino = currentTetromino.movedLeft(); |
el17ajf | 4:aa433f9865a6 | 19 | } |
el17ajf | 4:aa433f9865a6 | 20 | } |
el17ajf | 9:3a7776a29a11 | 21 | if (Input::buttonHit(Input::RIGHT)) { |
el17ajf | 9:3a7776a29a11 | 22 | if (grid.isSpaceForTetromino(currentTetromino.movedRight())) { |
el17ajf | 9:3a7776a29a11 | 23 | currentTetromino = currentTetromino.movedRight(); |
el17ajf | 13:59e17cab320a | 24 | } else { |
el17ajf | 13:59e17cab320a | 25 | printf("NO SPACE TO THE RIGHT"); |
el17ajf | 9:3a7776a29a11 | 26 | } |
el17ajf | 9:3a7776a29a11 | 27 | } |
el17ajf | 9:3a7776a29a11 | 28 | if (Input::buttonHit(Input::UP)) { |
el17ajf | 9:3a7776a29a11 | 29 | if (grid.isSpaceForTetromino(currentTetromino.rotatedClockwise())) { |
el17ajf | 9:3a7776a29a11 | 30 | currentTetromino = currentTetromino.rotatedClockwise(); |
el17ajf | 9:3a7776a29a11 | 31 | } |
el17ajf | 9:3a7776a29a11 | 32 | } |
el17ajf | 9:3a7776a29a11 | 33 | if (Input::buttonHit(Input::DOWN)) { |
el17ajf | 9:3a7776a29a11 | 34 | dropCurrentTetromino(); |
el17ajf | 9:3a7776a29a11 | 35 | } |
el17ajf | 4:aa433f9865a6 | 36 | } |
el17ajf | 4:aa433f9865a6 | 37 | |
el17ajf | 7:2e37bad816cb | 38 | void Game::moveCurrentTetrominoDown() { |
el17ajf | 7:2e37bad816cb | 39 | if (grid.isSpaceForTetromino(currentTetromino.movedDown())) { |
el17ajf | 4:aa433f9865a6 | 40 | currentTetromino = currentTetromino.movedDown(); |
el17ajf | 4:aa433f9865a6 | 41 | } else { |
el17ajf | 7:2e37bad816cb | 42 | grid.placeTetromino(currentTetromino); |
el17ajf | 7:2e37bad816cb | 43 | currentTetromino = Tetromino::getTetrominoOfType(nextTetrominoType); |
el17ajf | 13:59e17cab320a | 44 | nextTetrominoType = Tetromino::getRandomTetrominoType(); |
el17ajf | 4:aa433f9865a6 | 45 | } |
el17ajf | 2:0b5e289ef905 | 46 | } |
el17ajf | 2:0b5e289ef905 | 47 | |
el17ajf | 7:2e37bad816cb | 48 | void Game::dropCurrentTetromino() { |
el17ajf | 9:3a7776a29a11 | 49 | while (grid.isSpaceForTetromino(currentTetromino.movedDown())) { |
el17ajf | 9:3a7776a29a11 | 50 | currentTetromino = currentTetromino.movedDown(); |
el17ajf | 9:3a7776a29a11 | 51 | } |
el17ajf | 9:3a7776a29a11 | 52 | moveCurrentTetrominoDown(); |
el17ajf | 7:2e37bad816cb | 53 | } |
el17ajf | 7:2e37bad816cb | 54 | |
el17ajf | 2:0b5e289ef905 | 55 | void Game::draw() { |
el17ajf | 7:2e37bad816cb | 56 | currentTetromino.draw(); |
el17ajf | 4:aa433f9865a6 | 57 | grid.draw(); |
el17ajf | 2:0b5e289ef905 | 58 | } |