added functions to change pieces and determine their number of different angles

This commit is contained in:
Christian Kroll 2009-11-06 02:22:11 +00:00
parent 6aaf4b0c2e
commit 42bebccfba
2 changed files with 60 additions and 7 deletions

View File

@ -117,17 +117,52 @@ void tetris_piece_rotate(tetris_piece_t *pPc,
}
}
/* Function: tetris_piece_change
/* Function: tetris_piece_changeShape
* Description: changes the shape of a piece
* Argument pPc: piece to change
* Argument shape: the shape of interest
* Return value: void
*/
void tetris_piece_change(tetris_piece_t *pPc,
tetris_piece_shape_t shape)
void tetris_piece_changeShape(tetris_piece_t *pPc,
tetris_piece_shape_t shape)
{
assert(pPc != NULL);
assert((shape >= 0) && (shape <= TETRIS_PC_Z));
pPc->shape = shape;
}
/* Function: tetris_piece_changeAngle
* Description: changes the angle of a piece
* Argument pPc: piece to change
* Argument angle: the angle of interest
* Return value: void
*/
void tetris_piece_changeAngle(tetris_piece_t *pPc,
tetris_piece_angle_t angle)
{
assert(pPc != NULL);
assert((angle >= TETRIS_PC_ANGLE_0) && (angle <= TETRIS_PC_ANGLE_270));
pPc->angle = angle;
}
/* Function: tetris_piece_angleCount
* Description: returns the number of different angles
* Argument pPc: piece whose angle count is of interest
* Return value: number of different angles
*/
int8_t tetris_piece_angleCount(tetris_piece_t *pPc)
{
assert(pPc != NULL);
static const int8_t angleCounts[] PROGMEM = {2, 4, 1, 4, 4, 2, 2};
#ifdef __AVR__
return pgm_read_word(&angleCounts[pPc->shape]);
#else
return angleCounts[pPc->shape];
#endif
}

View File

@ -93,14 +93,32 @@ void tetris_piece_rotate(tetris_piece_t *pPc,
tetris_piece_rotation_t r);
/* Function: tetris_piece_change
/* Function: tetris_piece_changeShape
* Description: changes the shape of a piece
* Argument pPc: piece to change
* Argument shape: the shape of interest
* Return value: void
*/
void tetris_piece_change(tetris_piece_t *pPc,
tetris_piece_shape_t shape);
void tetris_piece_changeShape(tetris_piece_t *pPc,
tetris_piece_shape_t shape);
/* Function: tetris_piece_changeAngle
* Description: changes the angle of a piece
* Argument pPc: piece to change
* Argument angle: the angle of interest
* Return value: void
*/
void tetris_piece_changeAngle(tetris_piece_t *pPc,
tetris_piece_angle_t angle);
/* Function: tetris_piece_angleCount
* Description: returns the number of different angles
* Argument pPc: piece whose angle count is of interest
* Return value: int8_t
*/
int8_t tetris_piece_angleCount(tetris_piece_t *pPc);
#endif /*TETRIS_PIECE_H_*/