2012-05-07 06:56:00 +00:00
|
|
|
/**
|
|
|
|
* \addtogroup tetris
|
|
|
|
*@{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file piece.c
|
|
|
|
* @brief Implementation of the piece module.
|
|
|
|
* @author Christian Kroll
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
2010-08-24 23:00:40 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "../../compat/pgmspace.h"
|
|
|
|
#include "piece.h"
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
* construction/destruction *
|
|
|
|
*****************************/
|
|
|
|
|
|
|
|
tetris_piece_t *tetris_piece_construct(tetris_piece_shape_t s,
|
|
|
|
tetris_piece_angle_t a)
|
|
|
|
{
|
|
|
|
tetris_piece_t *p_piece = (tetris_piece_t*) malloc (sizeof(tetris_piece_t));
|
|
|
|
assert(p_piece != NULL);
|
|
|
|
|
|
|
|
p_piece->shape = s;
|
|
|
|
p_piece->angle = a;
|
|
|
|
|
|
|
|
return p_piece;
|
|
|
|
}
|
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
|
2008-12-03 05:40:16 +00:00
|
|
|
/****************************
|
|
|
|
* piece related functions *
|
|
|
|
****************************/
|
|
|
|
|
|
|
|
uint16_t tetris_piece_getBitmap(tetris_piece_t *pPc)
|
|
|
|
{
|
|
|
|
assert(pPc != NULL);
|
2010-08-24 23:00:40 +00:00
|
|
|
assert((pPc->angle < 4) && (pPc->shape < 7));
|
2008-12-03 05:40:16 +00:00
|
|
|
|
|
|
|
// Lookup table:
|
|
|
|
// A value in an array represents a piece in a specific angle (rotating
|
|
|
|
// clockwise from index 0).
|
2010-08-24 23:00:40 +00:00
|
|
|
static uint16_t const piece[][4] PROGMEM =
|
2008-12-03 05:40:16 +00:00
|
|
|
{{0x0F00, 0x2222, 0x0F00, 0x2222}, // LINE
|
|
|
|
{0x4E00, 0x4640, 0x0E40, 0x4C40}, // T
|
|
|
|
{0x0660, 0x0660, 0x0660, 0x0660}, // SQUARE
|
|
|
|
{0x2E00, 0x88C0, 0x0E80, 0xC440}, // L
|
|
|
|
{0x8E00, 0x6440, 0x0E20, 0x44C0}, // LBACK
|
|
|
|
{0x6C00, 0x4620, 0x6C00, 0x4620}, // S
|
|
|
|
{0xC600, 0x4C80, 0xC600, 0x4C80}}; // Z
|
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
return pgm_read_word(&piece[pPc->shape][pPc->angle]);
|
2008-12-03 05:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-30 22:47:44 +00:00
|
|
|
uint8_t tetris_piece_getAngleCount(tetris_piece_t *pPc)
|
2009-11-06 02:22:11 +00:00
|
|
|
{
|
|
|
|
assert(pPc != NULL);
|
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
static int8_t const angleCounts[] PROGMEM = {2, 4, 1, 4, 4, 2, 2};
|
2009-11-06 02:22:11 +00:00
|
|
|
|
2010-08-24 23:00:40 +00:00
|
|
|
return pgm_read_byte(&angleCounts[pPc->shape]);
|
2009-11-06 02:22:11 +00:00
|
|
|
}
|
2012-05-07 06:56:00 +00:00
|
|
|
|
|
|
|
/*@}*/
|