Browse Source

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

feature/2015
Christian Kroll 15 years ago
parent
commit
42bebccfba
  1. 41
      games/tetris/piece.c
  2. 26
      games/tetris/piece.h

41
games/tetris/piece.c

@ -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
}

26
games/tetris/piece.h

@ -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);
#endif /*TETRIS_PIECE_H_*/
/* 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_*/

Loading…
Cancel
Save