Skip to content

Commit

Permalink
Option to toggle the ghost piece
Browse files Browse the repository at this point in the history
  • Loading branch information
core1024 committed Aug 24, 2018
1 parent 586b30d commit 3ffe05b
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions game_tetris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
enum tet_option_t: uint8_t {
TET_OPT_ROT_DIR = 1,
TET_OPT_DROP_UP = 2,
TET_OPT_DROP_DN = 4
TET_OPT_DROP_DN = 4,
TET_OPT_HIDE_GHOST = 8
};

static uint8_t level_speed[NUM_LEVELS] = {53, 49, 45, 41, 37, 33, 28, 22, 17, 11, 10, 9, 8, 7, 6, 6, 5, 5, 4, 4, 3};
Expand Down Expand Up @@ -45,10 +46,16 @@ static struct data_t *data;
static unsigned long button_wait_time;

const uint8_t spriteMap[][7] PROGMEM = {
// RotR
{0b00001100, 0b00010010, 0b00100001, 0b00100001, 0b00001010, 0b00001100, 0b00001110},
// RotL
{0b00001110, 0b00001100, 0b00001010, 0b00100001, 0b00100001, 0b00010010, 0b00001100},
// -> Dn
{0b00001000, 0b00010000, 0b00100000, 0b01111111, 0b00100000, 0b00010000, 0b00001000},
{0b01000100, 0b01001000, 0b01010000, 0b01111111, 0b01010000, 0b01001000, 0b01000100}
// ->| Dn
{0b01000100, 0b01001000, 0b01010000, 0b01111111, 0b01010000, 0b01001000, 0b01000100},
// Ghost
{0b00000000, 0b01111100, 0b00111010, 0b01111111, 0b00111010, 0b01111100, 0b00000000}
};

static const uint16_t tetrominoes[7][4] = {
Expand Down Expand Up @@ -265,7 +272,7 @@ static void display_now_next() {
uint8_t dx3tx = dx + 3 * data->tx;

// Ghost
if(g > data->ty && bitRead(tetrominoes[data->tet_now_sel][data->tet_now_rot], i)) {
if(!(data->tet_option & TET_OPT_HIDE_GHOST) && g > data->ty && bitRead(tetrominoes[data->tet_now_sel][data->tet_now_rot], i)) {
gr->drawPixel(dx3tx, dy + 3 * g - 6);
}

Expand Down Expand Up @@ -326,25 +333,30 @@ static void game_on() {
}
gr->pollButtons();

if (gr->justPressed(B_BUTTON)) {
return;
}

if(gr->pressed(LEFT_BUTTON) && gr->pressed(RIGHT_BUTTON)) {
gr->clear();
gr->drawBitmap(28, 28, dPadBmp, 7, 7, WHITE);
gr->drawBitmap(78, 28, aBmp, 7, 7, WHITE);
gr->drawBitmap(78, 20, aBmp, 7, 7, WHITE);
gr->drawBitmap(78, 36, bBmp, 7, 7, WHITE);

gr->drawBitmap(28, 12, spriteMap[(data->tet_option & TET_OPT_DROP_UP) ? data->tet_option & TET_OPT_ROT_DIR : 3], 7, 7, WHITE);

gr->drawBitmap(28, 44, spriteMap[2 + !!(data->tet_option & TET_OPT_DROP_DN)], 7, 7, WHITE);

gr->drawBitmap(92, 28, spriteMap[data->tet_option & TET_OPT_ROT_DIR], 7, 7, WHITE);
gr->drawBitmap(92, 20, spriteMap[data->tet_option & TET_OPT_ROT_DIR], 7, 7, WHITE);

if(!(data->tet_option & TET_OPT_HIDE_GHOST)) {
gr->drawBitmap(92, 36, spriteMap[4], 7, 7, WHITE);
}

if(gr->justPressed(A_BUTTON)) {
data->tet_option ^= TET_OPT_ROT_DIR;
continue;
}
if (gr->justPressed(B_BUTTON)) {
data->tet_option ^= TET_OPT_HIDE_GHOST;
continue;
}
if(gr->justPressed(UP_BUTTON)) {
data->tet_option ^= TET_OPT_DROP_UP;
continue;
Expand All @@ -360,6 +372,10 @@ static void game_on() {
display_stats();
}

if (gr->justPressed(B_BUTTON)) {
return;
}

tetState &= ~TET_MOVED;

// Vertical Movement
Expand Down

0 comments on commit 3ffe05b

Please sign in to comment.