tank.c
来自「瑞星微公司RK27XX系列芯片的SDK开发包」· C语言 代码 · 共 2,089 行 · 第 1/5 页
C
2,089 行
{
if (timerleft % FRAME_PER_SEC == 0)
{
//MixerSetChannel(3, TankSoundTimer, 1, 1 );
timernum = timerleft / FRAME_PER_SEC;
DrawBmpIdEx(259, 10, (INT16U)(BID_char0 + timernum), 0, DSPM_Normal);
}
}
else if (timerleft == FRAME_PER_SEC - 1)
{
timerarearecover();//恢复屏幕
}
}
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(tankrect.x), (INT16U)(tankrect.y), (INT16U)(BID_borthflash00 + timerflag % 4), 0, DSPM_Transp);
if (tank->status == PLAYERTANKFLASHTIME - 1 || tank->timer == PLAYERTANKUNDEADTIME - 1)
{
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(tankrect.x), (INT16U)(tankrect.y), (INT16U)(BID_map000 + (gTankgame.barriesflag << 1) + 1), &r, DSPM_Transp);/*恢复屏幕*/
}
}
/************************************************************************
Desc : 子弹移动后地图的恢复
Param:无
Return:无
Global:bulletareamark、bulletarea
Author:xiexiuxie
*************************************************************************/
void PreBulletareaRecover(void)
{
int i;
UHRECT r;
for (i = 0;i < bulletareamark;i++)
{
r.x = bulletarea[i].x - 8;
r.y = bulletarea[i].y - 8;
r.w = 12;
r.h = 12;
if (bulletarea[i].x&0x0001 == 1) bulletarea[i].x = bulletarea[i].x + 1;
DrawBmpIdEx((INT16U)(bulletarea[i].x), (INT16U)(bulletarea[i].y), (INT16U)(BID_map000 + (gTankgame.barriesflag << 1) + 1), &r, DSPM_Transp);
}
if (i == bulletareamark)
{
bulletareamark = 0;
}
}
/************************************************************************
Desc : 玩家坦克的显示
Param:game1 游戏结构参数
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void PlayerTankShow(GameTankType *game1)
{
int i;
for (i = 0;i < 1;i ++)
{
if (game1->player[i].status < PLAYERTANKFLASHTIME)
{
game1->player[i].status++;
}
if (game1->player[i].timer > 0 && game1->player[i].timer < PLAYERTANKUNDEADTIME)
{
game1->player[i].timer++;
}
if ((game1->player[i].active) && (game1->player[i].status >= 7) && (game1->player[i].status <= PLAYERTANKFLASHTIME))
{
GameTankShowTank(&game1->player[i]); /*现显示坦克再加上光环*/
if (game1->player[i].status < PLAYERTANKFLASHTIME || (game1->player[i].timer > 0 && game1->player[i].timer < PLAYERTANKUNDEADTIME))
{
PlayerTankShowFlash(&game1->player[i]);
}
}
}
}
/************************************************************************
Desc : 敌人坦克的显示
Param:game1游戏结构参数
Return:无
Global:ENEMYMAX 敌人子弹数量
Author:xiexiuxie
*************************************************************************/
void EnemyTankShow(GameTankType *game1)
{
int i, timerleft, timernum;
for (i = 0;i < ENEMYMAX;i ++)
{
if ((game1->enemy[i]).status < 7)
{
game1->enemy[i].status++;
continue;
}
if (game1->enemy[i].active == 0)
{
continue;
}
if (game1->enemy[i].speed == 0)
{
if (game1->enemy[i].timer < ENEMYSPEEDZEROTIME)
{
game1->enemy[i].timer++;
EnemyTankSpeedZeroTimer = game1->enemy[i].timer;
}
timerleft = ENEMYSPEEDZEROTIME - game1->enemy[i].timer;
if (timerleft == ENEMYSPEEDZEROTIME - 1)
{
timerarearecover();
}
else if (timerleft < ENEMYSPEEDZEROTIME - 1 && timerleft > FRAME_PER_SEC*9)
{
;
}
else if (timerleft <= FRAME_PER_SEC*9 && timerleft >= FRAME_PER_SEC)
{
if (timerleft % FRAME_PER_SEC == 0)
{
//MixerSetChannel(3, TankSoundTimer, 1, 1 );
timernum = timerleft / FRAME_PER_SEC;
DrawBmpIdEx(259, 10, (INT16U)(BID_char0 + timernum), 0, DSPM_Normal);
}
else
{
;
}
}
else if (timerleft == 0)
{
timerarearecover();
switch (i)
{
case 0:
game1->enemy[i].speed = ENEMYTANKSPEED0;
break;
case 1:
game1->enemy[i].speed = ENEMYTANKSPEED1;
break;
case 2:
game1->enemy[i].speed = ENEMYTANKSPEED2;
break;
case 3:
game1->enemy[i].speed = ENEMYTANKSPEED3;
break;
case 4:
game1->enemy[i].speed = ENEMYTANKSPEED4;
break;
case 5:
game1->enemy[i].speed = ENEMYTANKSPEED5;
break;
case 6:
game1->enemy[i].speed = ENEMYTANKSPEED2;
break;
case 7:
game1->enemy[i].speed = ENEMYTANKSPEED3;
break;
default:
break;
}
}
}
GameTankShowTank(&game1->enemy[i]);
}
}
/************************************************************************
Desc : 坦克显示相关部分
Param:game1 游戏结构参数
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void TankShow(GameTankType *game1)
{
PreTankareaRecover();
PreBulletareaRecover();
PlayerTankShow(game1);
EnemyTankShow(game1);
}
/************************************************************************
Desc : 子弹显示
Param:bullet 火炮结构
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
BOOLEAN GameTankShowBullet(GameTankBullet *bullet)
{
UINT16 i;
int xx, yy;
i = 0;
xx = bullet->x;
yy = bullet->y;
switch (bullet->bullet_id)
{
case BID_bullet00:
i = 0;
break;
case BID_bullet10:
i = 1;
break;
case BID_bullet20:
i = 2;
break;
case BID_bullet30:
i = 3;
break;
default:
i = 0;
break;
}
if ((xx&0x0001 == 1) && xx < SCREENX + SCREENWID)
{
xx = xx + 1;
}
if (xx <= SCREENX + SCREENWID - bullet->wid)
{
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(xx), (INT16U)(yy), (INT16U)(BID_bullet00 + i*4 + bullet->dir), 0, DSPM_Transp);
}
return 1;
}
/************************************************************************
Desc : 玩家子弹的显示
Param:game1 游戏结构
Return:无
Global:BULLET_MAXNUM 玩家在地图上显示的子弹数目
Author:xiexiuxie
*************************************************************************/
void PlayerBulletShow(GameTankType *game1)
{
int i, n;
for (i = 0;i < 4;i++)
for (n = 0;n < BULLET_MAXNUM;n++)
{
if (game1->playerbullet[0][i][n].active)
{
GameTankShowBullet(&game1->playerbullet[0][i][n]);
}
}
}
/************************************************************************
Desc : 敌人子弹的显示
Param:game1 游戏结构
Return:无
Global:ENEMYBULLETMAX 敌人坦克数目
Author:xiexiuxie
*************************************************************************/
void EnemyBulletShow(GameTankType *game1)
{
int i;
for (i = 0;i < ENEMYBULLETMAX;i ++)
{
if (game1->enemybullet[i].active)
{
GameTankShowBullet(&game1->enemybullet[i]);
}
}
}
/************************************************************************
Desc : 子弹显示部分
Param:game1 游戏结构
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void BulletShow(GameTankType *game1)
{
PlayerBulletShow(game1);
EnemyBulletShow(game1);
}
/************************************************************************
Desc : 添加播放动画
Param:x 、y动画显示的x、y轴坐,moviedata要显示的动画结构,
game1 动画所在的游戏结构
Return:没有超过最大可显示动画量返回1,超过0
Global:无
Author:xiexiuxie
*************************************************************************/
int GameAddMovie(int x, int y, GameMovie *moviedata, GameTankType *game1) //将moviedata中的数据拷到gamemovie中去为下面的动画显示作准备
{
int i;
for (i = 0 ; i < MOVIEPLAYMAX ; i++)
{
if (!(game1->movie[ i ]).active)
{
memcpy(&game1->movie[ i ] , moviedata , sizeof(GameMovie));
(game1->movie[i]).x = x;
(game1->movie[i]).y = y;
break;
}
}
if (i < MOVIEPLAYMAX)
{
return(1);
}
else
{
return(0);
}
}
/************************************************************************
Desc : 显示动画
Param:game1 游戏结构
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void MovieShow(GameTankType *game1)
{
int i;
int x, y;
for (i = 0;i < MOVIEPLAYMAX;i++)
{
if (!(game1->movie[i]).active)//动画显示完成
{
continue;
}
else
{
if ((game1->movie[i]).movie_frame_flag < (game1->movie[i]).maxframe)//本动画是否显示完所有的帧
{
x = game1->movie[i].x;
y = game1->movie[i].y;
if ((game1->movie[i]).size == 12)//判断显示那个动画
{
if ((game1->movie[i]).x&0x0001 == 1)
{
x = (game1->movie[i]).x - 1;
}
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(x), (INT16U)(y), (INT16U)(BID_explode_bulletmovie_frame01 + (game1->movie[i]).movie_frame_flag), 0, DSPM_Transp);
}
else if ((game1->movie[i]).size == 16)
{
if ((game1->movie[i]).maxframe == 3)
{
if ((game1->movie[i]).x&0x0001 == 1)
{
x = (game1->movie[i]).x - 1;
}
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(x), (INT16U)(y), (INT16U)(BID_explode_tankmovie_frame01 + (game1->movie[i]).movie_frame_flag), 0, DSPM_Transp);
}
else if (game1->movie[i].maxframe == 8)
{
if ((game1->movie[i]).x&0x0001 == 1)
{
x = (game1->movie[i]).x - 1;
}
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(x), (INT16U)(y), (INT16U)(BID_burning01 + (game1->movie[i]).movie_frame_flag), 0, DSPM_Transp);
}
}
else if ((game1->movie[i]).size == 18)
{
if ((game1->movie[i]).x&0x0001 == 1)
{
x = (game1->movie[i]).x - 1;
}
gGuiDspTranspColor = COLOR_WHITE;
DrawBmpIdEx((INT16U)(x), (INT16U)(y), (INT16U)(BID_Borthmovie00 + (game1->movie[i]).movie_frame_flag), 0, DSPM_Transp);
}
(game1->movie[i]).movie_frame_flag++;
}
}
}
}
/************************************************************************
Desc : 动画结束后地图的恢复
Param:game1 游戏结构
Return:无
Global:无
Author:xiexiuxie
*************************************************************************/
void MovieRecover(GameTankType *game1)
{
int i, j, k;
int x, y;
UHRECT r;
for (i = 0;i < MOVIEPLAYMAX;i++)
{
if (!(game1->movie[i]).active)
{
continue;
}
else
{ /*目前波的是第几帧*/ /*最大帧数*/
if ((game1->movie[i]).movie_frame_flag == (game1->movie[i]).maxframe)
{
x = (game1->movie[i]).x;
y = (game1->movie[i]).y;
if (game1->movie[i].replay)
{
(game1->movie[i]).movie_frame_flag = 0;
continue;
}
(game1->movie[i]).active = 0;
if ((game1->movie[i]).size == 16)
{
if ((game1->movie[i]).x&0x0001 == 1)
{
x = (game1->movie[i]).x - 1;
}
r.x = x - 8;
r.y = (game1->movie[i]).y - 8;
r.w = 16;
r.h = 16;
// if((game1->movie[i]).x&0x0001==1) (game1->movie[i]).x=(game1->movie[i]).x+1;
DrawBmpIdEx((INT16U)(x), (INT16U)((game1->movie[i]).y), (INT16U)(BID_map000 + (gTankgame.barriesflag << 1) + 1), &r, DSPM_Transp);
}
else if ((game1->movie[i]).size == 18)
{
if ((game1->movie[i]).x&0x0001 == 1)
{
x = (game1->movie[i]).x - 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?