fixed: if a piece failed to rotate the bucket rotated nonetheless

This commit is contained in:
Christian Kroll 2011-03-07 00:31:18 +00:00
parent 8963b27a65
commit 28848358dd
2 changed files with 27 additions and 13 deletions

View File

@ -83,6 +83,9 @@ void tetris_main(tetris_variant_t const *const pVariantMethods)
tetris_view_setViewMode(pView, TETRIS_VIMO_RUNNING);
}
// helper variable which tells us whether the last move was possible
uint8_t bMoveOk = 1;
// what we do depends on what the input module tells us
switch (inCmd)
{
@ -109,22 +112,22 @@ void tetris_main(tetris_variant_t const *const pVariantMethods)
// player shifted the piece to the left
case TETRIS_INCMD_LEFT:
tetris_bucket_movePiece(pBucket, TETRIS_BUD_LEFT);
bMoveOk = tetris_bucket_movePiece(pBucket, TETRIS_BUD_LEFT);
break;
// player shifted the piece to the right
case TETRIS_INCMD_RIGHT:
tetris_bucket_movePiece(pBucket, TETRIS_BUD_RIGHT);
bMoveOk = tetris_bucket_movePiece(pBucket, TETRIS_BUD_RIGHT);
break;
// player rotated the piece clockwise
case TETRIS_INCMD_ROT_CW:
tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CW);
bMoveOk = tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CW);
break;
// player rotated the piece counter clockwise
case TETRIS_INCMD_ROT_CCW:
tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CCW);
bMoveOk = tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CCW);
break;
// the player decided to make an immediate drop
@ -150,7 +153,7 @@ void tetris_main(tetris_variant_t const *const pVariantMethods)
}
// inform variant object about the user's last move
pVariantMethods->setLastInput(pVariantData, inCmd);
pVariantMethods->setLastInput(pVariantData, inCmd, bMoveOk);
// inform the input module about the requested bearing of the
// variant object

View File

@ -73,21 +73,32 @@ tetris_highscore_index_t tetris_fp_getHighscoreIndex(void *pVariantData)
return TETRIS_HISCORE_FP;
}
/**
* change bearing depending on player's last input
* @param pVariantData the variant data object we want to modify
* @param inCmd the last issued command
* @param bMoveOk 1 if the last move was possible, otherwise 0
*/
void tetris_fp_setLastInput(void *pVariantData,
tetris_input_command_t inCmd)
tetris_input_command_t inCmd,
uint8_t bMoveOk)
{
assert (pVariantData != NULL);
tetris_standard_variant_t *pStdVariant =
(tetris_standard_variant_t *)pVariantData;
if (inCmd == TETRIS_INCMD_ROT_CW)
if (bMoveOk)
{
pStdVariant->nBearing += 1;
}
else if (inCmd == TETRIS_INCMD_ROT_CCW)
{
pStdVariant->nBearing += 3;
if (inCmd == TETRIS_INCMD_ROT_CW)
{
// piece rotated clockwise -> rotate bucket counter-clockwise
pStdVariant->nBearing += 3;
}
else if (inCmd == TETRIS_INCMD_ROT_CCW)
{
// piece rotated counter-clockwise -> rotate bucket clockwise
pStdVariant->nBearing += 1;
}
}
pStdVariant->nBearing %= 4;
}