|
|
@ -1,18 +1,15 @@
|
|
|
|
// tidx is an index into tetriminos. yoff and xoff are relative to the
|
|
|
|
// tidx is an index into tetriminos. yoff and xoff are relative to the
|
|
|
|
// terminal's origin. returns colored north-facing tetrimino on a plane.
|
|
|
|
// terminal's origin. returns colored north-facing tetrimino on a plane.
|
|
|
|
std::unique_ptr<ncpp::Plane> NewPiece() {
|
|
|
|
std::unique_ptr<ncpp::Plane> NewPiece() {
|
|
|
|
// "North-facing" tetrimino forms (form in which they are released from the
|
|
|
|
// "North-facing" tetrimino forms (form in which they are released from the top) are expressed in terms of
|
|
|
|
// top) are expressed in terms of two rows having between 2 and 4 columns.
|
|
|
|
// two rows having between 2 and 4 columns. We map each game column to four columns and each game row to two
|
|
|
|
// We map each game column to four columns and each game row to two rows. Each
|
|
|
|
// rows. Each byte of the texture maps to one 4x4 component block (and wastes 7 bits).
|
|
|
|
// byte of the texture maps to one 4x4 component block (and wastes 7 bits).
|
|
|
|
|
|
|
|
static const struct tetrimino {
|
|
|
|
static const struct tetrimino {
|
|
|
|
unsigned color;
|
|
|
|
unsigned color;
|
|
|
|
const char* texture;
|
|
|
|
const char* texture;
|
|
|
|
} tetriminos[] = { // OITLJSZ
|
|
|
|
} tetriminos[] = { // OITLJSZ
|
|
|
|
{ 0xcbc900, "****"}, { 0x009caa, " ****"}, { 0x952d98, " * ***"},
|
|
|
|
{ 0xcbc900, "****"}, { 0x009caa, " ****"}, { 0x952d98, " * ***"}, { 0xcf7900, " ****"},
|
|
|
|
{ 0xcf7900, " ****"}, { 0x0065bd, "* ***"}, { 0x69be28, " **** "},
|
|
|
|
{ 0x0065bd, "* ***"}, { 0x69be28, " **** "}, { 0xbd2939, "** **"} };
|
|
|
|
{ 0xbd2939, "** **"} };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int tidx = random() % 7;
|
|
|
|
const int tidx = random() % 7;
|
|
|
|
const struct tetrimino* t = &tetriminos[tidx];
|
|
|
|
const struct tetrimino* t = &tetriminos[tidx];
|
|
|
|
const size_t cols = strlen(t->texture);
|
|
|
|
const size_t cols = strlen(t->texture);
|
|
|
@ -27,8 +24,7 @@ std::unique_ptr<ncpp::Plane> NewPiece() {
|
|
|
|
n->set_fg(t->color);
|
|
|
|
n->set_fg(t->color);
|
|
|
|
n->set_bg_alpha(CELL_ALPHA_TRANSPARENT);
|
|
|
|
n->set_bg_alpha(CELL_ALPHA_TRANSPARENT);
|
|
|
|
n->set_base(channels, 0, "");
|
|
|
|
n->set_base(channels, 0, "");
|
|
|
|
y = 0;
|
|
|
|
y = 0; x = 0;
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0 ; i < strlen(t->texture) ; ++i){
|
|
|
|
for(size_t i = 0 ; i < strlen(t->texture) ; ++i){
|
|
|
|
if(t->texture[i] == '*'){
|
|
|
|
if(t->texture[i] == '*'){
|
|
|
|
if(n->putstr(y, x, "██") < 0){
|
|
|
|
if(n->putstr(y, x, "██") < 0){
|
|
|
|