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@9:3a7776a29a11, 2019-03-15 (annotated)
- Committer:
- el17ajf
- Date:
- Fri Mar 15 20:30:01 2019 +0000
- Revision:
- 9:3a7776a29a11
- Parent:
- 7:2e37bad816cb
- Child:
- 11:fba7d54fd36b
added more graphics methods
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 | 2:0b5e289ef905 | 3 | |
el17ajf | 2:0b5e289ef905 | 4 | Game::Game() { |
el17ajf | 7:2e37bad816cb | 5 | currentTetromino = Tetromino::getTetrominoOfType( |
el17ajf | 7:2e37bad816cb | 6 | Tetromino::getRandomTetrominoType()); |
el17ajf | 7:2e37bad816cb | 7 | nextTetrominoType = Tetromino::getRandomTetrominoType(); |
el17ajf | 2:0b5e289ef905 | 8 | } |
el17ajf | 2:0b5e289ef905 | 9 | |
el17ajf | 2:0b5e289ef905 | 10 | Game::~Game() { |
el17ajf | 6:a54df561f442 | 11 | |
el17ajf | 2:0b5e289ef905 | 12 | } |
el17ajf | 2:0b5e289ef905 | 13 | |
el17ajf | 2:0b5e289ef905 | 14 | void Game::over() { |
el17ajf | 2:0b5e289ef905 | 15 | |
el17ajf | 2:0b5e289ef905 | 16 | } |
el17ajf | 2:0b5e289ef905 | 17 | |
el17ajf | 2:0b5e289ef905 | 18 | void Game::update() { |
el17ajf | 9:3a7776a29a11 | 19 | if (Input::buttonHit(Input::LEFT)) { |
el17ajf | 7:2e37bad816cb | 20 | if (grid.isSpaceForTetromino(currentTetromino.movedLeft())) { |
el17ajf | 4:aa433f9865a6 | 21 | currentTetromino = currentTetromino.movedLeft(); |
el17ajf | 4:aa433f9865a6 | 22 | } |
el17ajf | 4:aa433f9865a6 | 23 | } |
el17ajf | 9:3a7776a29a11 | 24 | if (Input::buttonHit(Input::RIGHT)) { |
el17ajf | 9:3a7776a29a11 | 25 | if (grid.isSpaceForTetromino(currentTetromino.movedRight())) { |
el17ajf | 9:3a7776a29a11 | 26 | currentTetromino = currentTetromino.movedRight(); |
el17ajf | 9:3a7776a29a11 | 27 | } |
el17ajf | 9:3a7776a29a11 | 28 | } |
el17ajf | 9:3a7776a29a11 | 29 | if (Input::buttonHit(Input::UP)) { |
el17ajf | 9:3a7776a29a11 | 30 | if (grid.isSpaceForTetromino(currentTetromino.rotatedClockwise())) { |
el17ajf | 9:3a7776a29a11 | 31 | currentTetromino = currentTetromino.rotatedClockwise(); |
el17ajf | 9:3a7776a29a11 | 32 | } |
el17ajf | 9:3a7776a29a11 | 33 | } |
el17ajf | 9:3a7776a29a11 | 34 | if (Input::buttonHit(Input::DOWN)) { |
el17ajf | 9:3a7776a29a11 | 35 | dropCurrentTetromino(); |
el17ajf | 9:3a7776a29a11 | 36 | } |
el17ajf | 4:aa433f9865a6 | 37 | } |
el17ajf | 4:aa433f9865a6 | 38 | |
el17ajf | 7:2e37bad816cb | 39 | void Game::moveCurrentTetrominoDown() { |
el17ajf | 7:2e37bad816cb | 40 | if (grid.isSpaceForTetromino(currentTetromino.movedDown())) { |
el17ajf | 4:aa433f9865a6 | 41 | currentTetromino = currentTetromino.movedDown(); |
el17ajf | 4:aa433f9865a6 | 42 | } else { |
el17ajf | 7:2e37bad816cb | 43 | grid.placeTetromino(currentTetromino); |
el17ajf | 7:2e37bad816cb | 44 | currentTetromino = Tetromino::getTetrominoOfType(nextTetrominoType); |
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 | } |
el17ajf | 2:0b5e289ef905 | 59 | |
el17ajf | 2:0b5e289ef905 | 60 | void Game::nextLevel() { |
el17ajf | 2:0b5e289ef905 | 61 | |
el17ajf | 2:0b5e289ef905 | 62 | } |
el17ajf | 2:0b5e289ef905 | 63 | |
el17ajf | 2:0b5e289ef905 | 64 | void Game::startLevel(int level) { |
el17ajf | 2:0b5e289ef905 | 65 | |
el17ajf | 2:0b5e289ef905 | 66 | } |