diff --git a/tetris/src/game/tetromino.cc b/tetris/src/game/tetromino.cc index 2f0aeec..e5d5fd9 100644 --- a/tetris/src/game/tetromino.cc +++ b/tetris/src/game/tetromino.cc @@ -211,13 +211,25 @@ void Tetromino::moveRight(std::vector> grid) void Tetromino::hardDrop(const std::vector& boardBaseline) { + // Trim empty rows at bottom of the 4x4 bounding box + std::int16_t pieceBottom = y.begin; + for (auto row = y.begin; row <= y.end; ++row) { + for (auto col = x.begin; col <= x.end; ++col) { + if (matrix[row - y.begin][col - x.begin] != " ") { + pieceBottom = row; + break; + } + } + } + std::int16_t pieceHeight = pieceBottom - y.begin + 1; + std::int16_t highestY = boardBaseline[0].y; for (const auto& coord : boardBaseline) { if (coord.y < highestY) highestY = coord.y; } y.end = highestY; - y.begin = static_cast(y.end - matrix.size() + 1); + y.begin = static_cast(y.end - pieceHeight + 1); } void Tetromino::softDrop()