2008-12-03 05:40:16 +00:00
|
|
|
#ifndef TETRIS_PIECE_H_
|
|
|
|
#define TETRIS_PIECE_H_
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
* types *
|
|
|
|
*********/
|
|
|
|
|
|
|
|
typedef enum tetris_piece_shape_t
|
|
|
|
{
|
|
|
|
TETRIS_PC_LINE,
|
|
|
|
TETRIS_PC_T,
|
|
|
|
TETRIS_PC_SQUARE,
|
|
|
|
TETRIS_PC_L,
|
|
|
|
TETRIS_PC_LBACK,
|
|
|
|
TETRIS_PC_S,
|
|
|
|
TETRIS_PC_Z
|
|
|
|
}
|
|
|
|
tetris_piece_shape_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum tetris_piece_angle_t
|
|
|
|
{
|
|
|
|
TETRIS_PC_ANGLE_0,
|
|
|
|
TETRIS_PC_ANGLE_90,
|
|
|
|
TETRIS_PC_ANGLE_180,
|
|
|
|
TETRIS_PC_ANGLE_270
|
|
|
|
}
|
|
|
|
tetris_piece_angle_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum tetris_piece_rotation_t
|
|
|
|
{
|
|
|
|
TETRIS_PC_ROT_CW, // clockwise rotation
|
|
|
|
TETRIS_PC_ROT_CCW // counter clockwise rotation
|
|
|
|
}
|
|
|
|
tetris_piece_rotation_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct tetris_piece_t
|
|
|
|
{
|
|
|
|
tetris_piece_shape_t shape; // specifies the shape of the piece
|
|
|
|
tetris_piece_angle_t angle; // specifies one of 4 angels
|
|
|
|
}
|
|
|
|
tetris_piece_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
* construction/destruction *
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
/* Function: tetris_piece_construct
|
|
|
|
* Description: constructs a piece with the given attributes
|
|
|
|
* Argument s: shape of the piece (see tetris_piece_shape_t)
|
|
|
|
* Argument a: its angle (see tetris_piece_angel_t)
|
|
|
|
* Return value: pointer to a newly created piece
|
|
|
|
*/
|
|
|
|
tetris_piece_t *tetris_piece_construct(tetris_piece_shape_t s,
|
|
|
|
tetris_piece_angle_t a);
|
|
|
|
|
|
|
|
|
|
|
|
/* Function: tetris_piece_destruct
|
|
|
|
* Description: destructs a piece
|
|
|
|
* Argument pPc: pointer to the piece to be destructed
|
|
|
|
* Return value: void
|
|
|
|
*/
|
|
|
|
void tetris_piece_destruct(tetris_piece_t *pPc);
|
|
|
|
|
|
|
|
|
|
|
|
/****************************
|
|
|
|
* piece related functions *
|
|
|
|
****************************/
|
|
|
|
|
|
|
|
/* Function: tetris_piece_getBitmap
|
2009-10-31 15:15:00 +00:00
|
|
|
* Description: returns bitfield representation of the piece
|
2008-12-03 05:40:16 +00:00
|
|
|
* Argument pPc: piece from which the bitfield shuld be retrieved
|
|
|
|
* Return value: bitfield representation of the piece
|
|
|
|
* - nth nibble is nth row of the piece (from upper left)
|
|
|
|
* - the LSB of a nibble represents the left side of a row
|
|
|
|
*/
|
|
|
|
uint16_t tetris_piece_getBitmap(tetris_piece_t *pPc);
|
|
|
|
|
|
|
|
|
|
|
|
/* Function: tetris_piece_rotate
|
|
|
|
* Description: rotates a piece
|
|
|
|
* Argument pPc: piece to rotate
|
|
|
|
* Argument r: type of rotation (see tetris_piece_rotation_t)
|
|
|
|
* Return value: void
|
|
|
|
*/
|
|
|
|
void tetris_piece_rotate(tetris_piece_t *pPc,
|
|
|
|
tetris_piece_rotation_t r);
|
|
|
|
|
|
|
|
|
2009-11-06 02:22:11 +00:00
|
|
|
/* Function: tetris_piece_changeShape
|
2009-10-31 15:15:00 +00:00
|
|
|
* Description: changes the shape of a piece
|
|
|
|
* Argument pPc: piece to change
|
|
|
|
* Argument shape: the shape of interest
|
|
|
|
* Return value: void
|
|
|
|
*/
|
2009-11-06 02:22:11 +00:00
|
|
|
void tetris_piece_changeShape(tetris_piece_t *pPc,
|
|
|
|
tetris_piece_shape_t shape);
|
2009-10-31 15:15:00 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
|
2009-11-06 02:22:11 +00:00
|
|
|
/* 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_*/
|