Example #1
0
void HelloWorld::draw()
{
    //这里需要绘制格子了。。
    CCPoint pt1;
    CCPoint pt2;
    for (int i = 0 ; i < 16 ; i++)
    {
        for (int j =0 ; j < 8; j++) {
            int x = m_CurrentMapStartPos.y +j;
            int y = m_CurrentMapStartPos.x +i;
            if (map[x][y] != 1) {
                ccDrawColor4B(255, 0, 0, 125);
                
            }
            else
            {
                if(map[x][y] == 2){
                    ccDrawColor4B(0, 255, 255, 125);
                }
                else
                {
                    ccDrawColor4B(0, 255, 0, 125);
                }
                
            }
            pt1.x = i*64 ;
            pt1.y = j*64+m_border;
            pt2.x = (i+1)*64;
            pt2.y = (j+1)*64+m_border;
            ccDrawRect(pt1, pt2);
            
            {
               char  num[20];
               CCTexture2D* tex = new CCTexture2D();
               sprintf(num, "%d,%d",(int)m_CurrentMapStartPos.x + i,(int)m_CurrentMapStartPos.y +j);
                tex->initWithString(num, "Arial", 15);
               CCRect rect = CCRectMake(pt1.x,pt1.y,30,30);
               tex->drawInRect(rect);
               tex->autorelease();
            }
            
        }
    }
    
    char  PlayerPos[20];
    CCTexture2D* tex = new CCTexture2D();
    sprintf(PlayerPos, "playerPos:%d,%d",(int)m_CurrentPos.x,(int)m_CurrentPos.y);
    tex->initWithString(PlayerPos, "Arial", 15);
    CCRect rect = CCRectMake(10,700,100,30);
    tex->drawInRect(rect);
    tex->autorelease();
    
    char  CurrentmapstartPos[20];
    CCTexture2D* tex1 = new CCTexture2D();
    sprintf(CurrentmapstartPos, "CurrentmapstartPos:%d,%d",(int)m_CurrentMapStartPos.x,(int)m_CurrentMapStartPos.y);
    tex1->initWithString(CurrentmapstartPos, "Arial", 15);
    CCRect rect1 = CCRectMake(10,730,100,30);
    tex1->drawInRect(rect1);
    tex1->autorelease();
    


    CCLayer::draw();
    
    
}