示例#1
0
 void getColorBytes(unsigned char* bytes)
 {
     // 1000 byte color map
     unsigned char* bptr = bytes;
     for (int yb = 0; yb < yBlocks; yb++)
     {
         for (int xb = 0; xb < xBlocks; xb++)
         {
             unsigned char c1 = getBlockColor(xb, yb, 0);
             unsigned char c2 = getBlockColor(xb, yb, 1);
             unsigned char colorbyte = (c1 << 4) | c2;
             *bptr = colorbyte;
             bptr++;
         }
     }
 }
示例#2
0
static void capture_board(blockColor gameBoard[8][8])
{
    int x = 0, y = 0;

    /*! attempt to take a snapshot of the window */
    HRESULT hRet = pDDSysSurface7->BltFast(0, 0, pDDSurface7, &windowRect, DDBLTFAST_WAIT);

    /*! quit if failure */
    if(FAILED(hRet)) { return; }

    /*! iterate through each row */
    for(y=0;y<8;y++)
    {
        /*! calculate current block Y offset */
        int curY = baseY + eachH*y + quarH;

        /*! iterate through each column */
        for(x=0;x<8;x++)
        {
            /*! calculate current block X offset */
            int curX = baseX + eachW*x + quarW;

            /*! calculate current block average RGB */
            {
                int x2 = 0, y2 = 0;

                uint32 accumR = 0;
                uint32 accumG = 0;
                uint32 accumB = 0;

                for(y2=0;y2<halfH;y2++)
                {
                    /*! calculate current pixel Y offset */
                    int pixelY = curY + y2;

                    for(x2=0;x2<halfW;x2++)
                    {
                        /*! calculate current pixel X offset */
                        int pixelX = curX + x2;

                        /*! fetch current pixel value */
                        uint32 curPixel = rgb32[pixelY*windowWidth+pixelX];

                        /*! added to each RGB component's accumulator */
                        accumR += (curPixel & 0x00FF0000) >> 16;
                        accumG += (curPixel & 0x0000FF00) >>  8;
                        accumB += (curPixel & 0x000000FF) >>  0;
                    }
                }

                /*! calculate each RGB component's average */
                uint32 avgR = accumR / (halfW*halfH);
                uint32 avgG = accumG / (halfW*halfH);
                uint32 avgB = accumB / (halfW*halfH);

                /*! calculate average RGB */
                uint32 avgRGB = (avgR << 16) | (avgG << 8) | avgB;

                /*! retrieve current block color */
                blockColor curBlock = getBlockColor((double)avgR / 255.0, (double)avgG / 255.0, (double)avgB / 255.0);

                /*! update gameboard */
                gameBoard[y][x] = curBlock;
            }
        }
    }

    return;
}
示例#3
0
void GameController::CoordinateChanged(const QPoint &_coordinate)
{

    if(this->pipeManager->currentPipe==0)
        return;
    QPoint lastcoordinate = this->pipeManager->currentPipe->back();
    QColor _coordinateColor = getBlockColor(_coordinate);
    STATE _coordinateState = getBlockState(_coordinate);
    int distance = Distance(lastcoordinate,_coordinate);
    if((_coordinateState&CURRENT)==0&&(getBlockState(lastcoordinate)&ORIGIN)!=0&&getBlockColor(lastcoordinate)==this->pipeManager->currentPipe->Color&&this->pipeManager->currentPipe->size()>1)
        return;
    if(distance!=1)
    {
        if(distance<=5&&(_coordinateState&ORIGIN)==0)
            AutoSearchPath(_coordinate);
        return;
    }
    if((_coordinateState&WAY)==0)
    {
        if((_coordinateState&ORIGIN)==0)
        {
            setBlockState(_coordinate,WAY|CURRENT);
            pipeManager->currentPipe->push_back(_coordinate);
            emit ForwardPipe();
            emit UpdatePipeDisplay();
        }
        else
        {
            if(_coordinateColor==pipeManager->currentPipe->Color)
            {
                setBlockState(_coordinate,WAY|CURRENT);
                pipeManager->currentPipe->push_back(_coordinate);
                emit CompletePipe(pipeManager->currentPipe);
                emit UpdatePipeDisplay();
            }
        }
    }
    else
    {
        if((_coordinateState&CURRENT)!=0)
        {
            while(pipeManager->currentPipe->back()!=_coordinate)
            {
                QPoint backpoint = pipeManager->currentPipe->back();
                QColor backpointColor = getBlockColor(backpoint);
                setBlockState(backpoint,~CURRENT);
                if(backpointColor==GameData::BgColor || backpointColor==pipeManager->currentPipe->Color)
                    setBlockState(backpoint,~WAY);
                else
                {
                    setBlockState(backpoint,~BREAK);
                    Pipe* pipe = pipeManager->getPipe(backpointColor);
                    bool unable = false;
                    for(int i=0;i<pipe->size();++i)
                    {
                        STATE _state = getBlockState(pipe->at(i));
                        if((_state&BREAK)!=0)
                            unable = true;
                        if(unable && (_state&BREAK)==0)
                            setBlockState(pipe->at(i),~WAY);
                        else
                            setBlockState(pipe->at(i),WAY);
                    }
                }
                pipeManager->currentPipe->pop_back();
            }
            emit BackwardPipe();
            emit UpdatePipeDisplay();
        }
        else
        {
            if((_coordinateState&ORIGIN)!=0)
                return;
            Pipe* pipe = pipeManager->getPipe(_coordinateColor);
            setBlockState(_coordinate,WAY|CURRENT|BREAK);
            pipeManager->currentPipe->push_back(_coordinate);
            bool unable = false;
            for(int i=0;i<pipe->size();++i)
            {
                STATE _state = getBlockState(pipe->at(i));
                if((_state&BREAK)!=0)
                    unable = true;
                if(unable && (_state&BREAK)==0)
                    setBlockState(pipe->at(i),~WAY);
                else
                    setBlockState(pipe->at(i),WAY);
            }
            emit BreakPipe(pipe);
            emit UpdatePipeDisplay();
        }
    }
}
示例#4
0
 void getScreenBytes(unsigned char* bytes)
 {
     int c64bytes = getScreenBytesSize();
     memset(bytes, 0, c64bytes);
     int width = getWidth();
     int height = getHeight();
     
     for (int h = 0; h < height; h++)
     {
         for (int w = 0; w < width; w++)
         {
             //printf("src %d = %d\n", h*width+w, src[h*width+w]);
             
             int xblock = w / xBlockSize;
             int yblock = h / yBlockSize;
             
             Pixel* p = pixelAt(w, h);
             
             // determine bitmask based on the palette index
             // bgcolor = 0x00
             // fgcolor = 0x03
             // block color 0 = 0x01
             // block color 1 = 0x02
             unsigned char mask = 0;
             
             if (p->palette_index == bgcolor)
             {
                 mask = 0x00;
             }
             else if (p->palette_index == fgcolor)
             {
                 mask = 0x03;
             }
             else if (p->palette_index == getBlockColor(xblock, yblock, 0))
             {
                 mask = 0x01;
             }
             else if (p->palette_index == getBlockColor(xblock, yblock, 1))
             {
                 mask = 0x02;
             }
             else
             {
                 printf("this should not happen.");
             }
             
             // set bits in bitmap byte
             int screen_width = w*2;
             
             int row = h / 8;
             int c = screen_width / 8;
             int line = h & 7;
             int bit = 7 - (screen_width & 7);
             int byte = row*320 + c*8 + line;
             
             unsigned char b = bytes[byte];
             
             // raise 2 bits (fg color)
             bit--;
             if (bit < 0)
                 bit = 0;
             
             unsigned char shifted_mask = mask << bit;
             b = b | shifted_mask;
             bytes[byte] = b;
         }
     }
 }