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

📄 tank.c

📁 瑞星微公司RK27XX系列芯片的SDK开发包
💻 C
📖 第 1 页 / 共 5 页
字号:
*************************************************************************/
INT32U GetPositiveRand(INT16U maxValue)
{
    INT16U value;
#ifdef __arm
    value = GetRadomTank();
#else
    value = rand();
#endif



// value = rand();
    if (maxValue == 0)
    {
        return 0;
    }
    return value % maxValue;

}

/************************************************************************
Desc  : 根据分数适当的奖励
Param:GameTankType 坦克类型,flg 奖励设置参数
Return:无
Global:game.TankLeftAdd 奖励控制值
Author:xiexiuxie
*************************************************************************/
void GameTankScoreEncourage(GameTankType *game1, int flg)
{
    if (gTankgame.TankLeftAdd == flg)
    {
#if 0
        num = GetPositiveRand(100);
        if (num < 95)
        {
            return;
        }
#endif
        if (game1->playerleft[0] < 6)
        {
            game1->playerleft[0]++;
            gTankgame.TankLeftAdd += 1;
        }
    }
}

/************************************************************************
Desc  : 信息栏的显示
Param:game1 坦克类型
Return:无
Global:infshowflag 显示标志位
Author:xiexiuxie
*************************************************************************/
void GameTankInfShow(GameTankType *game1)
{
    int i, j, k;
    INT16 d;//INT16U d;
    UHRECT r;
    r.x = 21;
    r.y = 27;
    r.w = 10;
    r.h = 80;
    DrawBmpIdEx(259, 26, BID_infshow, &r, DSPM_Normal);
    /*================================*/
    d = game1->scores[0];
    /*************************************/
    if (d >= 48000)
    {
        GameTankScoreEncourage(game1, 3);
    }
    else if (d >= 36000)
    {
        GameTankScoreEncourage(game1, 2);
    }
    else if (d >= 24000)
    {
        GameTankScoreEncourage(game1, 1);
    }
    else if (d >= 12000)
    {
        GameTankScoreEncourage(game1, 0);
    }
    /*****************************************/
    for (i = 0;i < 6;i++)
    {
        if (d >= 0)
        {
            j = d % 10;
            DrawBmpIdEx(276, (INT16U)(50 + 10*i), (INT16U)(BID_char0 + j), NULL, DSPM_Normal);
            d = d / 10;
        }
    }
    /*================================*/
    k = game1->playerleft[0];//+1;
    DrawBmpIdEx(258, 109, (INT16U)(BID_char0 + k), NULL, DSPM_Normal);
    /*================================*/
    for (i = 0;i < 4;i++)
    {
        k = game1->enemyleft[i];//+1;
        DrawBmpIdEx(296, (INT16U)(138 - i*44), (INT16U)(BID_char0 + k), NULL, DSPM_Normal);
    }
    /*===============================*/
    if (((game1->player[0].tank_id >= BID_playertank11) && (game1->player[0].tank_id <= BID_playertank14)) || ((game1->player[0].tank_id >= BID_playertank31) && (game1->player[0].tank_id <= BID_playertank34)) || ((game1->player[0].tank_id >= BID_playertank51) && (game1->player[0].tank_id <= BID_playertank54)))
    {
        if (((game1->player[0].tank_id >= BID_playertank31) && (game1->player[0].tank_id <= BID_playertank34)))
        {
            switch (game1->player[0].life)
            {
                case 0:
                    i = 0;
                    break;
                case 50:
                    i = 1;
                    break;
                case 100:
                    i = 2;
                    break;
                case 150:
                    i = 3;
                    break;
                default:
                    i = 0;
                    break;
            }
            DrawBmpIdEx(259, 52, (INT16U)(BID_playerblood00 + i), NULL, DSPM_Normal);

            //DrawBmpFromSdram(TankBlood00[i],152,256,36,10,NULL,Normal);
        }
        else
        {
            switch (game1->player[0].life)
            {
                case 0:
                    i = 0;
                    break;
                case 50:
                    i = 1;
                    break;
                case 100:
                    i = 2;
                    break;
                case 150:
                    i = 3;
                    break;
                case 200:
                    i = 4;
                    break;
                default:
                    break;
            }
            DrawBmpIdEx(259, 46, (INT16U)(BID_playerblood10 + i), NULL, DSPM_Normal);

            //DrawBmpFromSdram(TankBlood10[i],152,256,42,10,NULL,Normal);
        }
    }
    else
    {
        switch (game1->player[0].life)
        {
            case 0:
                i = 0;
                break;
            case 50:
                i = 1;
                break;
            case 100:
                i = 2;
                break;
            case 150:
                i = 3;
                break;
            case 200:
                i = 4;
                break;
            case 250:
                i = 5;
                break;
            case 300:
                i = 6;
                break;
            default:
                break;
        }

        DrawBmpIdEx(259, 28, (INT16U)(BID_playerblood20 + i), NULL, DSPM_Normal);

        //DrawBmpFromSdram(TankBlood20[i],152,256,60,10,NULL,Normal);
    }
    /*===============================*/
    //DrawBmpIdEx( 232, 0, BID_tankgamewarning, NULL, DSPM_Normal );
    //DrawBmpIdEx( 259, 26, BID_infshow, &r, DSPM_Normal );
    infshowflag = 0;
}
/************************************************************************
Desc  : 每关开始的关数显示及效果处理
Param:win 游戏窗口指针
Return:无
Global:inpaintflag状态栏显示标志位,game.barriesflag关数
Author:xiexiuxie
*************************************************************************/
BOOLEAN barryshow(WINDOW *win)
{
    int m, n;
    UHRECT r, re;
    re.y = 0;
    re.x = 0;
    re.h = 224;
    re.w = 224;
    if (gInpaintflag <= SHOW_BACK_MAP)
    {
        r.y = 0;
        r.x = 0;
        r.h = 240;
        r.w = (gInpaintflag) * 32;
        DrawBmpIdEx(0, 0 , BID_background , &r , DSPM_Normal);
    }
    else
    {
        switch (gInpaintflag)
        {
            case SHOW_BACK_STAGE:
                DrawBmpIdEx(80, 80 , BID_backstage , 0, DSPM_Normal);
                break;
            case SHOW_STAGE_NUM:
                if (gTankgame.barriesflag < 9)
                {
                    DrawBmpIdEx(82, 63 , (INT16U)(BID_number0 + gTankgame.barriesflag + 1), 0, DSPM_Normal);
                }
                else if (gTankgame.barriesflag >= 9 && gTankgame.barriesflag < MAXBARRIER)
                {
                    n = (gTankgame.barriesflag + 1) / 10;
                    m = (gTankgame.barriesflag + 1) % 10;
                    DrawBmpIdEx(82, 63 , (INT16U)(BID_number0 + n), 0, DSPM_Normal);
                    DrawBmpIdEx(82, 42, (INT16U)(BID_number0 + m), 0, DSPM_Normal);
                }
                break;
            case SHOW_MAP_BACK:
                DrawBmpIdEx(8, 8 , (INT16U)(BID_map000 + (gTankgame.barriesflag << 1) + 1), &re, DSPM_Normal);
                break;
            case SHOW_MAP:
                gGuiDspTranspColor = COLOR_WHITE;
                DrawBmpIdEx(8, 8 , (INT16U)(BID_map000 + gTankgame.barriesflag*2), &re, DSPM_Transp);
                break;
            case SHOW_INFSHOW:
                DrawBmpIdEx(232, 0 , BID_infshow, 0, DSPM_Normal);
                break;
            default:
                break;
        }
    }
    gInpaintflag++;
    return FALSE;
}

/************************************************************************
Desc  : 坦克显示
Param:tank 坦克结构参数结构体
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void GameTankShowTank(GameTank *tank)
{
    UINT16 i;
    UHRECT tankrect;
    tankrect.x = tank->x;
    tankrect.y = tank->y;
    if (tank->tank_id >= BID_playertank11 && tank->tank_id <= BID_playertank61)
    {
        switch (tank->tank_id)
        {
            case BID_playertank11:
                i = 0;
                break;
            case BID_playertank21:
                i = 1;
                break;
            case BID_playertank31:
                i = 2;
                break;
            case BID_playertank41:
                i = 3;
                break;
            case BID_playertank51:
                i = 4;
                break;
            case BID_playertank61:
                i = 5;
                break;
            default:
                i = 0;
                break;
        }
        if (tankrect.x&0x0001 == 1 && tankrect.x <= 224 + 8)
        {
            tankrect.x = tankrect.x + 1;
        }
        gGuiDspTranspColor = COLOR_WHITE;
        DrawBmpIdEx((INT16U)tankrect.x, (INT16U)tankrect.y, (INT16U)(BID_playertank11 + i*4 + tank->dir), 0, DSPM_Transp);
    }
    if (tank->tank_id >= BID_enemytank01 && tank->tank_id <= BID_enemytank51)
    {
        switch (tank->tank_id)
        {
            case BID_enemytank01:
                i = 0;
                break;
            case BID_enemytank11:
                i = 1;
                break;
            case BID_enemytank21:
                i = 2;
                break;
            case BID_enemytank31:
                i = 3;
                break;
            case BID_enemytank41:
                i = 4;
                break;
            case BID_enemytank51:
                i = 5;
                break;
            default:
                i = 0;
                break;
        }
        if (tankrect.x&0x0001 == 1 && tankrect.x <= 224 + 8)
        {
            tankrect.x = tankrect.x + 1;
        }
        gGuiDspTranspColor = COLOR_WHITE;
        DrawBmpIdEx((INT16U)(tankrect.x), (INT16U)(tankrect.y), (INT16U)(BID_enemytank01 + i*4 + tank->dir), 0, DSPM_Transp);
    }
}
/************************************************************************
Desc  : 坦克移动后地图的恢复
Param:无
Return:无
Global:tankarea 坦克占用地图数组 ,  tankareamark
Author:xiexiuxie
*************************************************************************/
void PreTankareaRecover(void)
{
    int i;
    UHRECT r;
    for (i = 0;i < tankareamark;i++)
    {
        r.x = tankarea[i].x - 8;
        r.y = tankarea[i].y - 8;
        r.w = 16;
        r.h = 16;
        if (tankarea[i].x&0x0001 == 1)
            tankarea[i].x = tankarea[i].x + 1;
        DrawBmpIdEx((INT16U)(tankarea[i].x), (INT16U)(tankarea[i].y), (INT16U)(BID_map000 + (gTankgame.barriesflag << 1) + 1), &r, DSPM_Transp);
    }
    if (i == tankareamark)
    {
        tankareamark = 0;
    }
}
/************************************************************************
Desc  : 信息栏中时间显示区的恢复
Param:无
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void timerarearecover(void)
{
    UHRECT infrect;
    infrect.x = 21;
    infrect.y = 10;
    infrect.w = 15;
    infrect.h = 15;
    DrawBmpIdEx(259, 10, BID_infshow, &infrect, DSPM_Normal);
}
/************************************************************************
Desc  : 玩家坦克无敌光环的闪烁
Param:tank 坦克结构
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void PlayerTankShowFlash(GameTank *tank)
{
    int timerleft, timernum;
    UINT16 timerflag;
    UHRECT tankrect, r;
    tankrect.x = tank->x;
    tankrect.y = tank->y;
    r.x = tank->x - 8;
    r.y = tank->y - 8;
    r.w = tankrect.w = 16;
    r.h = tankrect.h = 16;
    if (tank->dir == 1 && (tankrect.x&0x0001 == 1) && tankrect.x <= 232)
    {
        tankrect.x = tankrect.x + 1;
    }
    else if (tank->dir == 3 && (tankrect.x&0x0001 == 1) && tankrect.x >= 8)
    {
        tankrect.x = tankrect.x - 1;
    }
    if (tank->status < PLAYERTANKFLASHTIME)
    {
        timerflag = tank->status;
    }
    else
    {
        timerflag = tank->timer;
        timerleft = PLAYERTANKUNDEADTIME - tank->timer;
        if (timerleft == PLAYERTANKUNDEADTIME - 1)
        {
            timerarearecover();
        }
        //else if(timerleft< PLAYERTANKUNDEADTIME-1&&timerleft>FRAME_PER_SEC*9)
        //{;}
        else if (timerleft <= FRAME_PER_SEC*9 && timerleft >= FRAME_PER_SEC)

⌨️ 快捷键说明

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