// RenderBoard(TetrisGame* game) - render the whole board that is currently 'set' void RenderBoard(TetrisGame* game) { //really simple - go through row by row, column by column and render the squares if necessary for(int row = 0; row < 21; row++) { for(int col = 0; col < 12; col++) { PlotBlock(game,GAME_BOARD_TOP_LEFT_X + col * BLOCK_SIZE,GAME_BOARD_TOP_LEFT_Y + row * BLOCK_SIZE,EMPTY); if(game->GameBoard[row][col] != EMPTY && game->GameBoard[row][col] != INVISIBLE && game->visibleLines[row]) { PlotBlock(game,GAME_BOARD_TOP_LEFT_X + col * BLOCK_SIZE,GAME_BOARD_TOP_LEFT_Y + row * BLOCK_SIZE,game->GameBoard[row][col]); } else if(game->GameBoard[row][col] == INVISIBLE) { PlotBlock(game,GAME_BOARD_TOP_LEFT_X + col * BLOCK_SIZE,GAME_BOARD_TOP_LEFT_Y + row * BLOCK_SIZE,game->GameBoard[row][col]); } } } }
//RenderBlock(TetrisGame* game,int x, int y,const int* block,bool rotate) - render the block void RenderBlock(TetrisGame* game,int x, int y,const int* block,bool rotate) { int offset = 0; //calculate an offset into the block data depending on the rotation index if(rotate) { offset = game->currentRotation * 16; } //for each of the 16 blocks 'plot' a block to the screen, pass in the x and y pixel vales for(int row = 0; row < 4; row++) { for(int col = 0; col < 4; col++) { if(block[offset + row * 4 + col] != EMPTY) { PlotBlock(game,x + col * BLOCK_SIZE ,y + row * BLOCK_SIZE,block[offset + row * 4 + col]); } } } }
ExtFunc int RefreshBoard(int scr) { int y, x, any = 0; unsigned int c; BlockType b; for (y = boardVisible[scr] - 1; y >= 0; --y) if ((c = changed[scr][y])) { if (robotEnable) { RobotCmd(0, "RowUpdate %d %d", scr, y); for (x = 0; x < boardWidth[scr]; ++x) { b = board[scr][y][x]; if (fairRobot) b = abs(b); RobotCmd(0, " %d", b); } RobotCmd(0, "\n"); } changed[scr][y] = 0; any = 1; for (x = 0; c; (c >>= 1), (++x)) if ((c & 1) && B_OLD(board[scr][y][x])!=oldBoard[scr][y][x]) { PlotBlock(scr, y, x, B_OLD(board[scr][y][x])); oldBoard[scr][y][x] = B_OLD(board[scr][y][x]); } } if (robotEnable) RobotTimeStamp(); for (x = 0; x < boardWidth[scr]; ++x) if (oldFalling[scr][x] != !!falling[scr][x]) { oldFalling[scr][x] = !!falling[scr][x]; PlotUnderline(scr, x, oldFalling[scr][x]); any = 1; } return any; }