|
@ -92,15 +92,11 @@ static void tetris_bucket_hoverStatus(tetris_bucket_t *pBucket) |
|
|
{ |
|
|
{ |
|
|
assert(pBucket != NULL); |
|
|
assert(pBucket != NULL); |
|
|
|
|
|
|
|
|
// if the piece touches the dump we ensure that the status is "gliding"
|
|
|
// status depends on whether the piece touches the dump or not
|
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn, pBucket->nRow + 1)) |
|
|
// NOTE: 0 == TETRIS_BUS_HOVERING, 1 == TETRIS_BUS_GLIDING,
|
|
|
{ |
|
|
// tetris_bucket_collision(...) either returns 0 or 1
|
|
|
pBucket->status = TETRIS_BUS_GLIDING; |
|
|
pBucket->status = tetris_bucket_collision(pBucket, pBucket->nColumn, |
|
|
} |
|
|
pBucket->nRow + 1); |
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
pBucket->status = TETRIS_BUS_HOVERING; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -177,7 +173,7 @@ tetris_piece_t *tetris_bucket_insertPiece(tetris_bucket_t *pBucket, |
|
|
pBucket->pPiece = pPiece; |
|
|
pBucket->pPiece = pPiece; |
|
|
|
|
|
|
|
|
// did we already collide with something?
|
|
|
// did we already collide with something?
|
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn, pBucket->nRow) == 1) |
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn, pBucket->nRow)) |
|
|
{ |
|
|
{ |
|
|
// game over man, game over!!
|
|
|
// game over man, game over!!
|
|
|
pBucket->status = TETRIS_BUS_GAMEOVER; |
|
|
pBucket->status = TETRIS_BUS_GAMEOVER; |
|
@ -243,19 +239,20 @@ void tetris_bucket_advancePiece(tetris_bucket_t *pBucket) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t tetris_bucket_movePiece(tetris_bucket_t *pBucket, |
|
|
uint8_t tetris_bucket_movePiece(tetris_bucket_t *pBucket, |
|
|
tetris_bucket_direction_t direction) |
|
|
tetris_bucket_direction_t nDirection) |
|
|
{ |
|
|
{ |
|
|
assert(pBucket != NULL); |
|
|
assert(pBucket != NULL); |
|
|
|
|
|
|
|
|
// a piece can only be moved if it is still hovering or gliding
|
|
|
// a piece can only be moved if it is still hovering or gliding
|
|
|
assert((pBucket->status == TETRIS_BUS_HOVERING) || |
|
|
assert((pBucket->status == TETRIS_BUS_HOVERING) || |
|
|
(pBucket->status == TETRIS_BUS_GLIDING)); |
|
|
(pBucket->status == TETRIS_BUS_GLIDING)); |
|
|
|
|
|
// only the values of the direction enumeration are allowed
|
|
|
|
|
|
assert((nDirection == TETRIS_BUD_LEFT) || (nDirection = TETRIS_BUD_RIGHT)); |
|
|
|
|
|
|
|
|
int8_t nOffset = (direction == TETRIS_BUD_LEFT) ? -1 : 1; |
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn + nDirection, |
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn + nOffset, |
|
|
|
|
|
pBucket->nRow) == 0) |
|
|
pBucket->nRow) == 0) |
|
|
{ |
|
|
{ |
|
|
pBucket->nColumn += nOffset; |
|
|
pBucket->nColumn += nDirection; |
|
|
|
|
|
|
|
|
// are we gliding?
|
|
|
// are we gliding?
|
|
|
tetris_bucket_hoverStatus(pBucket); |
|
|
tetris_bucket_hoverStatus(pBucket); |
|
@ -277,8 +274,8 @@ uint8_t tetris_bucket_rotatePiece(tetris_bucket_t *pBucket, |
|
|
|
|
|
|
|
|
tetris_piece_rotate(pBucket->pPiece, rotation); |
|
|
tetris_piece_rotate(pBucket->pPiece, rotation); |
|
|
|
|
|
|
|
|
// does the rotated piece cause a collision?
|
|
|
// does the rotated piece collide with something?
|
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn, pBucket->nRow) != 0) |
|
|
if (tetris_bucket_collision(pBucket, pBucket->nColumn, pBucket->nRow)) |
|
|
{ |
|
|
{ |
|
|
// in that case we revert the rotation
|
|
|
// in that case we revert the rotation
|
|
|
tetris_piece_rotate(pBucket->pPiece, rotation == TETRIS_PC_ROT_CW ? |
|
|
tetris_piece_rotate(pBucket->pPiece, rotation == TETRIS_PC_ROT_CW ? |
|
|