⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eros.c

📁 基于QUALCOMM BREW平台实现俄罗斯方块游戏功能
💻 C
📖 第 1 页 / 共 5 页
字号:
    int temp = pMe->current_block;
    //AECHAR szText[] ={'N','e','x','t','\0','S','c','o','r','e','\0'},game_title[30]={0};
    AECHAR szText[20] ={0},szScore[20] ={0},game_title[30]={0};

    AECHAR game_score[16]={0};
    ISHELL_LoadResString(pMe->a.m_pIShell,gsErosResFile, IDS_GAME_TITLE, game_title, sizeof(game_title));
    ISHELL_LoadResString(pMe->a.m_pIShell, gsErosResFile, IDS_NEXT, szText, sizeof(szText));
    ISHELL_LoadResString(pMe->a.m_pIShell, gsErosResFile, IDS_SCORE, szScore, sizeof(szScore));
    rect.x=0;
    rect.y=0+BREW_APP_Y+MENU_TITLE_HEIGHT;
    //wuhaoyong modify
    //rect.dx=120; //screen width
    rect.dx=pMe->m_Rect.dx; //screen width
    rect.dy=pMe->block_height;
    IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
                      &rect,
                      pMe->frame_color,// RGBVAL
                      pMe->frame_color,// RGBVAL
                      IDF_RECT_FRAME | IDF_RECT_FILL);
    rect.x=0;
    rect.y=MAP_HEIGHT*pMe->block_height+pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT;
    rect.dx=pMe->m_Rect.dx;//screen width
    rect.dy=pMe->block_height;
    IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
                      &rect,
                      pMe->frame_color,// RGBVAL
                      pMe->frame_color,// RGBVAL
                      IDF_RECT_FRAME | IDF_RECT_FILL);
    rect.x=MAP_WIDTH*pMe->block_width+pMe->block_width;
    rect.y=pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT;
    rect.dx=pMe->block_width;
    rect.dy=MAP_HEIGHT*pMe->block_height;

    IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
                      &rect,
                      pMe->frame_color,
                      pMe->frame_color,
                      IDF_RECT_FRAME | IDF_RECT_FILL);
    rect.x=0;
    rect.y=pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT;
    rect.dx=pMe->block_width;
    rect.dy=MAP_HEIGHT*pMe->block_height;
    IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
                      &rect,
                      pMe->frame_color,// RGBVAL
                      pMe->frame_color,// RGBVAL
                      IDF_RECT_FRAME | IDF_RECT_FILL);
    rect.x=pMe->m_Rect.dx-pMe->block_width;
    rect.y=pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT;
    rect.dx=pMe->block_width;
    rect.dy=MAP_HEIGHT*pMe->block_height;
    IDISPLAY_DrawRect(pMe->a.m_pIDisplay,
                      &rect,
                      pMe->frame_color,// RGBVAL
                      pMe->frame_color,// RGBVAL
                      IDF_RECT_FRAME | IDF_RECT_FILL);
    IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                      AEE_FONT_LARGE,       // Use BOLD font
                      szText,              // Text - Normally comes from resource
                      -1,                  // -1 = Use full string length
                      MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width,   // x-cordinate
                      pMe->block_height+4+BREW_APP_Y+MENU_TITLE_HEIGHT,                   // y-cordinate
                      NULL,                // No clipping
                      0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                      AEE_FONT_LARGE,       // Use BOLD font
                      szScore,//szText+5,              // Text - Normally comes from resource
                      -1,                  // -1 = Use full string length
                      MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width,  // x-cordinate
                      MAP_HEIGHT*pMe->block_height-48+pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT,                   // y-cordinate
                      NULL,                // No clipping
                      0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    Eros_DrawLevel(pMe);
#if 0

    IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                      AEE_FONT_BOLD,       // Use BOLD font
                      game_title,              // Text - Normally comes from resource
                      -1,                  // -1 = Use full string length
                      0,   // x-cordinate
                      MAP_HEIGHT*pMe->block_height+pMe->block_height+pMe->block_height,                   // y-cordinate
                      NULL,                // No clipping
                      IDF_ALIGN_CENTER );
#endif

    HSComFunc_DrawTitleBGImage(pMe->a.m_pIDisplay,0,FALSE);
    Eros_DrawTitleText(pMe,IDS_GAME_TITLE);
    up_Itoa(game_score,(uint64)pMe->score);
    IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                      AEE_FONT_BOLD,       // Use BOLD font
                      game_score,              // Text - Normally comes from resource
                      -1,                  // -1 = Use full string length
                      //MAP_WIDTH*pMe->block_width+6+pMe->block_width,   // x-cordinate
                      //MAP_HEIGHT*pMe->block_height-20+pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT,                   // y-cordinate
                      MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width,   // x-cordinate
                      MAP_HEIGHT*pMe->block_height-20+pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT,                   // y-cordinate
                      NULL,                // No clipping
                      0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
    
    GenerateBlock(pMe,pMe->next_block);
    for (i=0; i<4; i++)
    {
        for (j=0; j<4; j++)
        {
            if (pMe->block[i][j] !=0)
                write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,pMe->color_table[pMe->block[i][j]],black);
            else
            {
                write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,RGB_NONE,noblack);
            }
        }
    }
    GenerateBlock(pMe,temp);
    
    //IDISPLAY_Update(pMe->a.m_pIDisplay);//wuhaoyong20070608
}
//=================================================================
//Function: generatenew
//Description: generate a new block
//Side effect: none
//=================================================================
void GenerateNew(eros * pMe)       /*generate a new block*/
{int i,j;
    int temp = pMe->next_block;
    uint32   dwTime = GET_UPTIMEMS();
    pMe->next_block=pMe->x_size+pMe->y_size+pMe->block_x+dwTime;
    pMe->next_block=pMe->next_block%pMe->difficult_level+pMe->a0;
    pMe->next_block=pMe->next_block%pMe->difficult_level+1;
    pMe->a0=0;

    GenerateBlock(pMe,pMe->next_block);
    // for(i=0;i<4;i++)
    // for(j=0;j<4;j++)
    // write_video(pMe,(map_line+i)*pMe->block_width,(map_col+j)*pMe->block_width,noblack);
    for (i=0; i<4; i++)
    {
        for (j=0; j<4; j++)
        {
            if (pMe->block[i][j] !=0)
                write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,pMe->color_table[pMe->block[i][j]],black);
            else
            {
                write_video(pMe,(pMe->map_line+2+i)*pMe->block_width+pMe->block_width,(j)*pMe->block_height+pMe->block_height+24,RGB_NONE,noblack);
            }
        }
    }
    GenerateBlock(pMe,temp);
    pMe->block_x = 4;
    pMe->block_y = 0;
    if (!CanPut(pMe))
    {
        pMe->gameover=1;
    }
}
//=====================================================================
//Function: putblock
//Description: put a block into map
//Side effect: none
//=====================================================================
void PutBlock(eros * pMe)    /* put block data into map*/
{int i,j;
    for (i=0; i<4; i++)
    {
        for (j=0; j<4; j++)
        {
            if (pMe->block[i][j] !=0)
                pMe->map[pMe->block_x+i][pMe->block_y+j] = pMe->block[i][j];
        }
    }

    DeleteRow(pMe);
}
//======================================================================
//Function: rotateblock
//Description: rotate the current block at the clockwise
//Side effect: none
//======================================================================
void RotateBlock(eros * pMe) /*rotate the block*/
{
    int old_block = pMe->current_block;
    pMe->current_block += 10;
    if (pMe->current_block > 40)
        pMe->current_block -= 40;
    GenerateBlock(pMe,pMe->current_block);
    if (!CanPut(pMe))
    {
        pMe->current_block = old_block;
        GenerateBlock(pMe,pMe->current_block);
    }
}
//======================================================================
//Function canput
//Description: determine whether block is out of the map and go down the bottom of map
//Side effect: none
//======================================================================

int CanPut(eros * pMe)     /*check if block have been out of the range*/
{int i,j;
    for (i=0; i<4; i++)
    {
        for (j=0; j<4; j++)
        {
            if (pMe->block[i][j] !=0)
            {
                if (pMe->block_x + i > pMe->map_line-1)
                    return 0;
                if (pMe->block_x + i < 0)
                    return 0;
                if (pMe->block_y + j > pMe->map_col-1)
                    return 0;
                if (pMe->block_y + j < 0)
                    return 0;
                if (pMe->map[pMe->block_x+i][pMe->block_y+j] != 0)
                    return 0;
            }
        }
    }
    return 1;
}
//===============================================================
//Function: drawmap
//Description: refresh the whole map
//Side effect: play with the display
//===============================================================
void DrawMap(eros * pMe)  /*draw map*/
{int i,j;
    for (i=0; i<pMe->map_line; i++)
    {
        for (j=0; j<pMe->map_col; j++)
        {
            if (pMe->map[i][j] !=0)
            {
                write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,pMe->color_table[pMe->map[i][j]],black);
            }
            else
                write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,RGB_NONE,noblack);
        }
    }

    for (i=0; i<pMe->x_size; i++)
    {
        for (j=0; j<pMe->y_size; j++)
        {
            if (pMe->block[i][j] != 0)
                write_video(pMe,(pMe->block_x+i)*pMe->block_width+pMe->block_width,(pMe->block_y+j)*pMe->block_width+pMe->block_height,pMe->color_table[pMe->block[i][j]],black);
        }
    }
    if(pMe->gameover==1)
    {
        //wuhaoyong add
        {
            int i,j;
            for (i=0; i<pMe->map_line; i++)
            {
                for (j=0; j<pMe->map_col; j++)
                {
                    //if (pMe->map[i][j] !=0)
                    //{
                    //    write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,pMe->color_table[pMe->map[i][j]],black);
                    //}
                    //else
                    write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,RGB_BLACK,black);
                }
            }
        }
        return;
    }
}
//===================================================================
//Function: deleterow
//Description: delete one more rows
//Side effect: play with the display
//===================================================================
void DeleteRow(eros * pMe)  /*delete a line meet the requirement*/
{
    int sum, i, j,k,del = 0;
    //int a[]={0,1,3,5,7};
    AECHAR game_score[8];
    for (i=pMe->map_col-1; i>=0; i--)
    {
        sum = 0;
        for (j=0; j<pMe->map_line; j++)
            sum += pMe->map[j][i]?1:0;
        if (sum == pMe->map_line)
        {
            for (j=i; j>=1; j--)
                for (k=0; k<pMe->map_line; k++)
                    pMe->map[k][j] = pMe->map[k][j-1];
            i++;
            del++;
        }
    }

    if(del!=0)
    {
        //ISHELL_Beep(pMe->a.m_pIShell,  BEEP_ERROR, TRUE);
        pMe->dels += del;
        //pMe->score+=del*10+(del-1)*2+(pMe->dels/10)*5;
        pMe->score+=del*1+(del-1)*1+(pMe->dels/10000)*1;
        up_Itoa(game_score,(uint64)pMe->score);
        IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                          AEE_FONT_LARGE,       // Use BOLD font
                          game_score,              // Text - Normally comes from resource
                          -1,                  // -1 = Use full string length
                          MAP_WIDTH*pMe->block_width+1+pMe->block_width+pMe->block_width,   // x-cordinate
                          MAP_HEIGHT*pMe->block_height-20+pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT,                   // y-cordinate
                          NULL,                // No clipping
                          0);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
        //add by wuhaoyong
        if(pMe->score>=99999)
        {
            pMe->gameover=1;
        }
    }
}
//game over
boolean Gameover(eros * pMe,uint32 r_color,uint32 g_color, uint32 b_color)  /*draw map*/
{
    pMe->m_nState=STATE_GAMEOVER;
    pMe->m_continue=0;
    eros_SaveScene(pMe);
    return Eros_CreatNotifyWin(pMe,HSNOTIFYWIN_ASK,IDS_RESTART);
#if 0

    int i,j;
    AECHAR game_over[] ={'G','a','m','e',' ','O','v','e','r','!','\0'};
    for (i=0; i<pMe->map_line; i++)
    {
        for (j=0; j<pMe->map_col; j++)
        {
            write_video(pMe,(i)*pMe->block_width+pMe->block_width,(j)*pMe->block_width+pMe->block_height,MAKE_RGB(r_color, g_color, b_color),black);
        }
    }
    Eros_WriteScoreFile(pMe);
    IDISPLAY_DrawText(pMe->a.m_pIDisplay,    // Display instance
                      AEE_FONT_BOLD,       // Use BOLD font
                      game_over,              // Text - Normally comes from resource
                      -1,                  // -1 = Use full string length
                      pMe->block_height,   // x-cordinate
                      MAP_HEIGHT*pMe->block_height/2,// y-cordinate
                      NULL,                // No clipping
                      IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
#endif
}

boolean GamePass(eros * pMe,uint32 r_color,uint32 g_color, uint32 b_color)  /*draw map*/
{
    pMe->m_nState=STATE_GAMEPASS;
    pMe->m_continue=0;
    eros_SaveScene(pMe);
    return Eros_CreatNotifyWin(pMe,HSNOTIFYWIN_OK,IDS_PASS);
#if 0

    int i,j;
    AECHAR game_over

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -