X-Git-Url: http://git.shiar.nl/netris.git/blobdiff_plain/02d0eeb0e0a5f43971cf687eac35dcedc59a0247..HEAD:/board.c diff --git a/board.c b/board.c index f1d159f..71ad1dc 100644 --- a/board.c +++ b/board.c @@ -23,71 +23,140 @@ #include "board.h" static const char shapes[7][4][4][4] = { - { { {0x00, 0x00, 0x00, 0x00}, {0x47, 0xC7, 0x97, 0x00}, - {0x00, 0x00, 0x27, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //sharp horizontal - { {0x00, 0x17, 0x00, 0x00}, {0x00, 0x37, 0x00, 0x00}, - {0x47, 0xA7, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //blunt vertical J - { {0x17, 0x00, 0x00, 0x00}, {0x67, 0xC7, 0x87, 0x00}, - {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //blunt horizontal - { {0x00, 0x57, 0x87, 0x00}, {0x00, 0x37, 0x00, 0x00}, - {0x00, 0x27, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //J (yellow) - - { { {0x00, 0x00, 0x00, 0x00}, {0x53, 0xC3, 0x83, 0x00}, - {0x23, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //sharp horizontal - { {0x43, 0x93, 0x00, 0x00}, {0x00, 0x33, 0x00, 0x00}, - {0x00, 0x23, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //sharp vertical - { {0x00, 0x00, 0x13, 0x00}, {0x43, 0xC3, 0xA3, 0x00}, - {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //blunt horizontal - { {0x00, 0x13, 0x00, 0x00}, {0x00, 0x33, 0x00, 0x00}, - {0x00, 0x63, 0x83, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //L (cyan) - - { { {0x00, 0x00, 0x00, 0x00}, {0x48, 0xD8, 0x88, 0x00}, - {0x00, 0x28, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //pointing down - { {0x00, 0x18, 0x00, 0x00}, {0x48, 0xB8, 0x00, 0x00}, - {0x00, 0x28, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //pointing left - { {0x00, 0x18, 0x00, 0x00}, {0x48, 0xE8, 0x88, 0x00}, - {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //pointing up - { {0x00, 0x18, 0x00, 0x00}, {0x00, 0x78, 0x88, 0x00}, - {0x00, 0x28, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //T (white) - - { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x52, 0x82, 0x00}, - {0x42, 0xA2, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, - { {0x12, 0x00, 0x00, 0x00}, {0x62, 0x92, 0x00, 0x00}, - {0x00, 0x22, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, - { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x52, 0x82, 0x00}, - {0x42, 0xA2, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep - { {0x12, 0x00, 0x00, 0x00}, {0x62, 0x92, 0x00, 0x00}, - {0x00, 0x22, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //S (green) - - { { {0x00, 0x00, 0x00, 0x00}, {0x46, 0x96, 0x00, 0x00}, - {0x00, 0x66, 0x86, 0x00}, {0x00, 0x00, 0x00, 0x00} }, - { {0x00, 0x16, 0x00, 0x00}, {0x56, 0xA6, 0x00, 0x00}, - {0x26, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, - { {0x00, 0x00, 0x00, 0x00}, {0x46, 0x96, 0x00, 0x00}, - {0x00, 0x66, 0x86, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep - { {0x00, 0x16, 0x00, 0x00}, {0x56, 0xA6, 0x00, 0x00}, - {0x26, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //Z (red) - - { { {0x00, 0x00, 0x00, 0x00}, {0x44, 0xC4, 0xC4, 0x84}, - {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //lieing - { {0x00, 0x14, 0x00, 0x00}, {0x00, 0x34, 0x00, 0x00}, - {0x00, 0x34, 0x00, 0x00}, {0x00, 0x24, 0x00, 0x00} }, //standing - { {0x00, 0x00, 0x00, 0x00}, {0x44, 0xC4, 0xC4, 0x84}, - {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep - { {0x00, 0x14, 0x00, 0x00}, {0x00, 0x34, 0x00, 0x00}, - {0x00, 0x34, 0x00, 0x00}, {0x00, 0x24, 0x00, 0x00} } }, //I, stick (blue) - - { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00}, - {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} }, - { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00}, - {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep - { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00}, - {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep - { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00}, - {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} } } //O, square (purple) + /* + * 4 rotations of 4x4 pixels per shape + * high nibble signifies joinage (left, right, top, bottom, from MSB) + * low nibble identifies block type (typically 2..8) + */ + + // J + { { { 0, 0, 0, 0000}, + {0x47, 0xC7, 0x97, 0000}, + { 0, 0, 0x27, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x17, 0, 0000}, + { 0, 0x37, 0, 0000}, + {0x47, 0xA7, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { {0x17, 0, 0, 0000}, + {0x67, 0xC7, 0x87, 0000}, + { 0, 0, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x57, 0x87, 0000}, + { 0, 0x37, 0, 0000}, + { 0, 0x27, 0, 0000}, + {0000, 0000, 0000, 0000} } }, + + // L + { { { 0, 0, 0, 0000}, + {0x53, 0xC3, 0x83, 0000}, + {0x23, 0, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { {0x43, 0x93, 0, 0000}, + { 0, 0x33, 0, 0000}, + { 0, 0x23, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0, 0x13, 0000}, + {0x43, 0xC3, 0xA3, 0000}, + { 0, 0, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x13, 0, 0000}, + { 0, 0x33, 0, 0000}, + { 0, 0x63, 0x83, 0000}, + {0000, 0000, 0000, 0000} } }, + + // T + { { { 0, 0, 0, 0000}, + {0x48, 0xD8, 0x88, 0000}, + { 0, 0x28, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x18, 0, 0000}, + {0x48, 0xB8, 0, 0000}, + { 0, 0x28, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x18, 0, 0000}, + {0x48, 0xE8, 0x88, 0000}, + { 0, 0, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x18, 0, 0000}, + { 0, 0x78, 0x88, 0000}, + { 0, 0x28, 0, 0000}, + {0000, 0000, 0000, 0000} } }, + + // S + { { { 0, 0, 0, 0000}, + { 0, 0x52, 0x82, 0000}, + {0x42, 0xA2, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { {0x12, 0, 0, 0000}, + {0x62, 0x92, 0, 0000}, + { 0, 0x22, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0, 0, 0000}, + { 0, 0x52, 0x82, 0000}, + {0x42, 0xA2, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { {0x12, 0, 0, 0000}, + {0x62, 0x92, 0, 0000}, + { 0, 0x22, 0, 0000}, + {0000, 0000, 0000, 0000} } }, + + // Z + { { { 0, 0, 0, 0000}, + {0x46, 0x96, 0, 0000}, + { 0, 0x66, 0x86, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x16, 0, 0000}, + {0x56, 0xA6, 0, 0000}, + {0x26, 0, 0, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0, 0, 0000}, + {0x46, 0x96, 0, 0000}, + { 0, 0x66, 0x86, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0x16, 0, 0000}, + {0x56, 0xA6, 0, 0000}, + {0x26, 0, 0, 0000}, + {0000, 0000, 0000, 0000} } }, + + // I + { { { 0, 0, 0, 0}, + {0x44, 0xC4, 0xC4, 0x84}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0} }, + { { 0, 0x14, 0, 0}, + { 0, 0x34, 0, 0}, + { 0, 0x34, 0, 0}, + { 0, 0x24, 0, 0} }, + { { 0, 0, 0, 0}, + {0x44, 0xC4, 0xC4, 0x84}, + { 0, 0, 0, 0}, + { 0, 0, 0, 0} }, + { { 0, 0x14, 0, 0}, + { 0, 0x34, 0, 0}, + { 0, 0x34, 0, 0}, + { 0, 0x24, 0, 0} } }, + + // O + { { { 0, 0, 0, 0000}, + { 0, 0x55, 0x95, 0000}, + { 0, 0x65, 0xA5, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0, 0, 0000}, + { 0, 0x55, 0x95, 0000}, + { 0, 0x65, 0xA5, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0, 0, 0000}, + { 0, 0x55, 0x95, 0000}, + { 0, 0x65, 0xA5, 0000}, + {0000, 0000, 0000, 0000} }, + { { 0, 0, 0, 0000}, + { 0, 0x55, 0x95, 0000}, + { 0, 0x65, 0xA5, 0000}, + {0000, 0000, 0000, 0000} } } }; -int ShapeIterate(char s, int scr, int y, int x, ShapeDrawFunc func) +int shape_iterate(char s, int scr, int y, int x, ShapeDrawFunc func) { //Draw a certain shape using int i, j, result; char type, rotation; @@ -103,8 +172,6 @@ int ShapeIterate(char s, int scr, int y, int x, ShapeDrawFunc func) } -float stdOptions[7] = {1, 1, 1, 1, 1, 1, 1}; //stdOptions - char ChooseOption(float options[7]) { //Return a random piece with given piece weight int i; @@ -123,7 +190,7 @@ static unsigned char oldBoard[MAX_SCREENS][MAX_BOARD_HEIGHT][MAX_BOARD_WIDTH]; static unsigned int changed[MAX_SCREENS][MAX_BOARD_HEIGHT]; static int shadowy; -void ClearField(int scr) +void player_empty(int scr) { //Empty the whole field (all blocks BT_none) int y, x; @@ -133,7 +200,7 @@ void ClearField(int scr) } } -unsigned char GetBlock(int scr, int y, int x) +unsigned char block_get(int scr, int y, int x) { //Returns the block on field at position (x,y) if (y < 0 || x < 0 || x >= Players[scr].boardWidth) return BT_wall; @@ -143,7 +210,7 @@ unsigned char GetBlock(int scr, int y, int x) return board[scr][y][x]; } -void SetBlock(int scr, int y, int x, unsigned char type) +static void block_set(int scr, int y, int x, unsigned char type) { if (y >= 0 && y < Players[scr].boardHeight && x >= 0 && x < Players[scr].boardWidth) { @@ -152,167 +219,172 @@ void SetBlock(int scr, int y, int x, unsigned char type) } } -int RefreshBoard(int scr) +int player_draw(int scr) { //draw changes to screen int y, x, any = 0; unsigned int c; for (y = Players[scr].boardVisible - 1; y >= 0; y--) - if ((c = changed[scr][y])) { //line changed + if ((c = changed[scr][y])) { // line changed for (x = 0; c; (c >>= 1), x++) if (c & 1 && board[scr][y][x] != oldBoard[scr][y][x]) { - PlotBlock(scr, y, x, board[scr][y][x]); + block_draw_window(scr, y, x, board[scr][y][x]); oldBoard[scr][y][x] = board[scr][y][x]; } - changed[scr][y] = 0; //reset + changed[scr][y] = 0; // reset any = 1; } //changed row return any; } -int GlanceFunc(int scr, int y, int x, unsigned char type) +int block_iter_set_status(int scr, int y, int x, unsigned char type) { - PlotBlockXY(y, x, type); + block_draw_status(y, x, type); return 0; } -int ShadowFunc(int scr, int y, int x, unsigned char type) +static int block_iter_shadow(int scr, int y, int x, unsigned char type) { //draw shadow - SetBlock(scr, y, x, BT_shadow); + block_set(scr, y, x, BT_shadow); return 0; } -int PlotFunc(int scr, int y, int x, unsigned char type) +static int block_iter_set(int scr, int y, int x, unsigned char type) { - SetBlock(scr, y, x, type); + block_set(scr, y, x, type); return 0; } -void PlotShape(char shape, int scr, int y, int x, int shadow) + +void shape_draw(char shape, int scr, int y, int x, int shadow) { //put shape on field if (shadow) { for (shadowy = y - 1; shadowy >= 0; shadowy--) - if (!ShapeFits(shape, scr, shadowy, x)) + if (!shape_get(shape, scr, shadowy, x)) break; - ShapeIterate(shape, scr, shadowy + 1, x, ShadowFunc); + shape_iterate(shape, scr, shadowy + 1, x, block_iter_shadow); } //draw shadow - ShapeIterate(shape, scr, y, x, PlotFunc); + shape_iterate(shape, scr, y, x, block_iter_set); } -int EraseFunc(int scr, int y, int x, unsigned char type) +static int block_iter_erase(int scr, int y, int x, unsigned char type) { - SetBlock(scr, y, x, BT_none); + block_set(scr, y, x, BT_none); return 0; } -void EraseShape(char shape, int scr, int y, int x, int shadow) + +void shape_erase(char shape, int scr, int y, int x, int shadow) { //remove block from field - ShapeIterate(shape, scr, y, x, EraseFunc); - if (shadow && scr == me) //draw shadow - ShapeIterate(shape, scr, shadowy + 1, x, EraseFunc); + shape_iterate(shape, scr, y, x, block_iter_erase); + if (shadow && scr == me) // draw shadow + shape_iterate(shape, scr, shadowy + 1, x, block_iter_erase); } -int CollisionFunc(int scr, int y, int x, unsigned char type) +static int block_iter_get(int scr, int y, int x, unsigned char type) { - return GetBlock(scr, y, x) > BT_none; + return block_get(scr, y, x) > BT_none; } -int ShapeFits(char shape, int scr, int y, int x) + +int shape_get(char shape, int scr, int y, int x) { //check if there's nothing in the way - return !ShapeIterate(shape, scr, y, x, CollisionFunc); + return !shape_iterate(shape, scr, y, x, block_iter_get); } -int VisibleFunc(int scr, int y, int x, unsigned char type) +static int block_iter_visible(int scr, int y, int x, unsigned char type) { return (y >= 0 && y < Players[scr].boardVisible && x >= 0 && x < Players[scr].boardWidth); } -int ShapeVisible(char shape, int scr, int y, int x) +int shape_visible(char shape, int scr, int y, int x) { - return ShapeIterate(shape, scr, y, x, VisibleFunc); + return shape_iterate(shape, scr, y, x, block_iter_visible); } -int MovePiece(int scr, int deltaY, int deltaX) +int player_move(int scr, int deltaY, int deltaX) { int result; - EraseShape(Players[scr].curShape, scr, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); - result = ShapeFits(Players[scr].curShape, scr, Players[scr].curY + deltaY, + result = shape_get(Players[scr].curShape, scr, Players[scr].curY + deltaY, Players[scr].curX + deltaX); if (result) { Players[scr].curY += deltaY; Players[scr].curX += deltaX; } - PlotShape(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); return result; } -int RotatePiece(int scr, int dir) +int player_rotate(int scr, int dir) { char newshape; int result; - EraseShape(Players[scr].curShape, scr, Players[scr].curY, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); /* (inc|dec)rement only 3 least significant bits which indicate rotation */ newshape = (Players[scr].curShape & 252) + (((Players[scr].curShape & 3) + dir) & 3); - result = ShapeFits(newshape, scr, Players[scr].curY, Players[scr].curX); + result = shape_get(newshape, scr, Players[scr].curY, Players[scr].curX); if (!result) { + // move if it doesn't fit anymore short int slideX; for (slideX = 0; slideX < 2; slideX = -slideX) { - if (slideX >= 0) slideX++; //slide more - if (result = ShapeFits(newshape, scr, Players[scr].curY, + // slide left and right + if (slideX >= 0) slideX++; // slide more + if (result = shape_get(newshape, scr, Players[scr].curY, Players[scr].curX+slideX)) break; - } //slide left and right + } if (result) Players[scr].curX += slideX; - } //try to fit if it doesn't + } if (result) Players[scr].curShape = newshape; - PlotShape(Players[scr].curShape, scr, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); return result; } -int DropPiece(int scr) +int player_drop(int scr) { int count = 0; - EraseShape(Players[scr].curShape, scr, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); - while (ShapeFits(Players[scr].curShape, scr, + while (shape_get(Players[scr].curShape, scr, Players[scr].curY - 1, Players[scr].curX)) { Players[scr].curY--; count++; } - PlotShape(Players[scr].curShape, scr, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 0); return count; } -int BlockFree(int scr, int x, int y, unsigned char z) +static int block_free(int scr, int x, int y, unsigned char z) { //Check if blocks are empty below block (x,y) and sticking to (x,y) mask unsigned char curblock; - if (y == 0) return 0; //at bottom - curblock = GetBlock(scr, y, x) & z; - if (curblock & 0x10 && !BlockFree(scr, x, y-1, z & 0xD0)) return 0; - if (curblock & 0x20 && !BlockFree(scr, x, y+1, z & 0xE0)) return 0; - if (curblock & 0x40 && !BlockFree(scr, x+1, y, z & 0x70)) return 0; - if (curblock & 0x80 && !BlockFree(scr, x-1, y, z & 0xB0)) return 0; - if ((z = GetBlock(scr, y-1, x)) & 0x20) return 1; //stuck to block below - if (z > BT_none) return 0; //some other piece below - return 1; //nothing below + if (y == 0) return 0; // at bottom + curblock = block_get(scr, y, x) & z; + if (curblock & 0x10 && !block_free(scr, x, y-1, z & 0xD0)) return 0; + if (curblock & 0x20 && !block_free(scr, x, y+1, z & 0xE0)) return 0; + if (curblock & 0x40 && !block_free(scr, x+1, y, z & 0x70)) return 0; + if (curblock & 0x80 && !block_free(scr, x-1, y, z & 0xB0)) return 0; + if ((z = block_get(scr, y-1, x)) & 0x20) return 1; // stuck to block below + if (z > BT_none) return 0; // some other piece below + return 1; // nothing below } -int BlockFall(int scr, int x, int y, unsigned char z) +static int block_down(int scr, int x, int y, unsigned char z) { //Drop down block (x,y) and those sticking to it mask - if (GetBlock(scr, y, x) & z & 0x10) BlockFall(scr, x, y-1, z & 0xD0); - if (GetBlock(scr, y, x) & z & 0x20) BlockFall(scr, x, y+1, z & 0xE0); - if (GetBlock(scr, y, x) & z & 0x40) BlockFall(scr, x+1, y, z & 0x70); - if (GetBlock(scr, y, x) & z & 0x80) BlockFall(scr, x-1, y, z & 0xB0); - SetBlock(scr, y-1, x, GetBlock(scr, y, x)); - SetBlock(scr, y, x, BT_none); + if (block_get(scr, y, x) & z & 0x10) block_down(scr, x, y-1, z & 0xD0); + if (block_get(scr, y, x) & z & 0x20) block_down(scr, x, y+1, z & 0xE0); + if (block_get(scr, y, x) & z & 0x40) block_down(scr, x+1, y, z & 0x70); + if (block_get(scr, y, x) & z & 0x80) block_down(scr, x-1, y, z & 0xB0); + block_set(scr, y-1, x, block_get(scr, y, x)); + block_set(scr, y, x, BT_none); } -int CheckFall(int scr) +int player_down(int scr) { //Drop any free blocks on field int xloop, x, x2, y, fallen = 0; unsigned char z; @@ -320,82 +392,78 @@ int CheckFall(int scr) if (!Game.gravity) return 0; for (y = Players[scr].boardHeight - 1; y > 0; y--) for (x = 0; x < Players[scr].boardWidth; x++) { - if ((z = GetBlock(scr, y, x)) > BT_none && (z & 0xA0) == 0) { - //doesn't stick left/up => topleft block - if (BlockFree(scr, x, y, 0xF0)) { - BlockFall(scr, x, y, 0xF0); + if ((z = block_get(scr, y, x)) > BT_none && (z & 0xA0) == 0) { + // block present which doesn't stick left/up => topleft block + if (block_free(scr, x, y, 0xF0)) { + block_down(scr, x, y, 0xF0); // move blocks down fallen++; - } //move blocks down + } } //block present - } //handle line + } return fallen; } -int LineIsFull(int scr, int y) +static int player_linecheck(int scr, int y) { //return 0 if any blocks present on line int x; for (x = 0; x < Players[scr].boardWidth; x++) - if (GetBlock(scr, y, x) <= BT_none) + if (block_get(scr, y, x) <= BT_none) return 0; return 1; } -void CopyLine(int scr, int from, int to) +static void player_linecopy(int scr, int from, int to) { //move blocks on line to line int x; if (from != to) for (x = 0; x < Players[scr].boardWidth; ++x) - SetBlock(scr, to, x, GetBlock(scr, from, x)); + block_set(scr, to, x, block_get(scr, from, x)); } -int ClearFullLines(int scr) +int player_lineclear(int scr) { //remove full lines, return lines cleared int from, to, x, linescleared = 0; do { from = to = 0; while (to < Players[scr].boardHeight) { - while (LineIsFull(scr, from)) { - from++; //skip + while (player_linecheck(scr, from)) { + from++; // skip for (x = 0; x 1) - SetBlock(scr, from-2, x, GetBlock(scr, from-2, x) & 0xDF); - } //don't stick blocks to line which we'll remove - } //full lines - CopyLine(scr, from++, to++); + block_set(scr, from-2, x, block_get(scr, from-2, x) & 0xDF); + } + } + player_linecopy(scr, from++, to++); } linescleared += from - to; - } while (CheckFall(scr)); + } while (player_down(scr)); return linescleared; } -void FreezePiece(int scr) -{ - // remove me! :) -} - -void InsertJunk(int scr, int color, int count, int column) +void player_lineadd(int scr, int color, int count, int column) { //add junklines with hole at to by team int y, x; - EraseShape(Players[scr].curShape, scr, + shape_erase(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, 1); for (y = Players[scr].boardHeight - count - 1; y >= 0; --y) - CopyLine(scr, y, y + count); + player_linecopy(scr, y, y + count); for (y = 0; y < count; ++y) for (x = 0; x < Players[scr].boardWidth; ++x) - SetBlock(scr, y, x, x == column ? BT_none : color + 1 + block_set(scr, y, x, x == column ? BT_none : color + 1 + 0x40 * (x != column-1 && x < Players[scr].boardWidth-1) + 0x80 * (x != column+1 && x > 0)); - Players[scr].curY += count; //move piece up.. + Players[scr].curY += count; // move piece up.. for (y = 0; y < count; ++y) - if (ShapeFits(Players[scr].curShape, scr, Players[scr].curY - 1, Players[scr].curX)) - Players[scr].curY--; //..and down again as far as possible + if (shape_get(Players[scr].curShape, scr, Players[scr].curY - 1, Players[scr].curX)) + Players[scr].curY--; // ...and down again as far as possible else break; - PlotShape(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, + shape_draw(Players[scr].curShape, scr, Players[scr].curY, Players[scr].curX, scr == me); }