Skip to content

Commit bb32cf7

Browse files
fix: update position & current rotation index after tet rotation
This was a very silly oversight I made that has been causing the pieces to incorrectly rotate.
1 parent f56322c commit bb32cf7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tetris/tetrimino.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ func (t *Tetrimino) MoveRight(matrix *Matrix) error {
166166
return nil
167167
}
168168

169+
// Returns true if the tetrimino can move down one row.
170+
// This checks if the bottom row of the tetrimino is at the bottom of the matrix or if the cells below the bottom row are occupied.
169171
func (t *Tetrimino) CanMoveDown(matrix Matrix) bool {
170172
bottomRow := len(t.Cells) - 1
171173
for col := range t.Cells[bottomRow] {
@@ -233,7 +235,9 @@ func (t *Tetrimino) Rotate(matrix *Matrix, clockwise bool) error {
233235
}
234236

235237
if rotated.canRotate(matrix) {
238+
t.Pos = rotated.Pos
236239
t.Cells = rotated.Cells
240+
t.CurrentRotation = rotated.CurrentRotation
237241
}
238242

239243
err = matrix.AddTetrimino(t)

0 commit comments

Comments
 (0)