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
- Committer:
- el17ajf
- Date:
- 2019-03-17
- Revision:
- 11:fba7d54fd36b
- Parent:
- 9:3a7776a29a11
- Child:
- 13:59e17cab320a
File content as of revision 11:fba7d54fd36b:
#include "Game.h" #include "Input.h" Game::Game() { currentTetromino = Tetromino::getTetrominoOfType( Tetromino::getRandomTetrominoType()); nextTetrominoType = Tetromino::getRandomTetrominoType(); } Game::~Game() { } void Game::update() { if (Input::buttonHit(Input::LEFT)) { if (grid.isSpaceForTetromino(currentTetromino.movedLeft())) { currentTetromino = currentTetromino.movedLeft(); } } if (Input::buttonHit(Input::RIGHT)) { if (grid.isSpaceForTetromino(currentTetromino.movedRight())) { currentTetromino = currentTetromino.movedRight(); } } if (Input::buttonHit(Input::UP)) { if (grid.isSpaceForTetromino(currentTetromino.rotatedClockwise())) { currentTetromino = currentTetromino.rotatedClockwise(); } } if (Input::buttonHit(Input::DOWN)) { dropCurrentTetromino(); } } void Game::moveCurrentTetrominoDown() { if (grid.isSpaceForTetromino(currentTetromino.movedDown())) { currentTetromino = currentTetromino.movedDown(); } else { grid.placeTetromino(currentTetromino); currentTetromino = Tetromino::getTetrominoOfType(nextTetrominoType); } } void Game::dropCurrentTetromino() { while (grid.isSpaceForTetromino(currentTetromino.movedDown())) { currentTetromino = currentTetromino.movedDown(); } moveCurrentTetrominoDown(); } void Game::draw() { currentTetromino.draw(); grid.draw(); }