接二:
void Flip()
{
RECT window;
POINT point;
GetClientRect(hWnd,&window);
point.x=0;point.y=0;
::ClientToScreen(hWnd,&point);
//move the window,the leaf along 
OffsetRect(&window,point.x,point.y);
result=pPSur->Blt(&window,pBBuf,&backrect ,DDBLT_WAIT, NULL);
if(result == DDERR_SURFACELOST)
pPSur->Restore();
return;
}void DrawPlane()
{
if(gamestate!=START)
return;
static int planenum ;
static unsigned int oldtime=0; if(planenum!=myplane.livenum)
{
oldtime=GetTickCount();
planenum=myplane.livenum;
myplane.ifsuper=true;
myplane.cancontrol=false;
myplane.position.x=backwidth/2-30;
myplane.position.y=backrect.bottom;
}
if(myplane.ifsuper==true)
if(GetTickCount() > oldtime+3000)
 myplane.ifsuper=false;
if(myplane.cancontrol==false)
{
if(myplane.position.y>backrect.bottom-100)
{
myplane.position.y-=myplane.speed;
myplane.pose=1;
}
else
myplane.cancontrol=true;
}
else
{
if(myplane.position.x<65)
myplane.position.x=65;
if(myplane.position.x>backwidth-65-50)
myplane.position.x=backwidth-65-50;
if(myplane.position.y<65)
myplane.position.y=65;
if(myplane.position.y>backheight-65-60)
myplane.position.y=backheight-65-60;
//line206
// desc.dwWidth=backwidth=forewidth+130;
    //desc.dwHeight=backheight=foreheight+130;
}
if( myplane.ifsuper==true)
{
static int ot=0;
if(GetTickCount()-ot>30)
ot=GetTickCount();
else
return;
}
//draw my plane
RECT rect;
GetRect(&rect,myplane.position.x,myplane.position.y,50,60);
result=pBBuf->Blt(&rect,pOPlaPlane[myplane.pose],NULL,DDBLT_WAIT|DDBLT_KEYSRC,NULL);
if(result==DDERR_SURFACELOST)
pBBuf->Restore();
}void DrawMap()
{
const int mapx=700,mapy=640;
static int posx=175,posy=640;
RECT rectto,rectfrom;
GetRect(&rectfrom,posx,0,forewidth,foreheight);
GetRect(&rectto,0,0,forewidth,foreheight);
pBBuf->Blt(&rectto,pOPlaMap,&rectfrom,DDBLT_WAIT|DDBLT_KEYSRC,NULL);
pBBuf->Restore();

}void DrawText()
{
RECT rect;
char temp[100];
COLORREF preColor; if(gamestate==INIT)
{
pBBuf->GetDC(&hdc);
SetBkMode(hdc,TRANSPARENT);
preColor=SetTextColor(hdc,RGB(255,0,0));
sprintf(temp,"skywar-HERO");
TextOut(hdc,200,250,temp,strlen(temp));
TextOut(hdc,200,270,"press enter to start",25);
SetTextColor(hdc,RGB(255,255,0));
TextOut(hdc,150,300,"the game is a study instance,not bussiness",50);
SetTextColor(hdc,preColor);
pBBuf->ReleaseDC(hdc);
//gamestart
}
if(gamestate==START)
{
for(int i=0;i<myplane.livenum;i++)
{
GetRect(&rect,backrect.left+10+i*25,backrect.bottom-30,20,20);
result=pBBuf->Blt(&rect,pOPlaPlane[1],NULL,DDBLT_WAIT|DDBLT_KEYSRC  ,NULL);
if(result == DDERR_SURFACELOST)
pBBuf->Restore();
}
GetRect(&rect,backrect.right-60,backrect.bottom-30,20,20);
result=pBBuf->Blt(&rect,pOPlaEnemy,NULL,DDBLT_WAIT|DDBLT_KEYSRC , NULL);
if(result == DDERR_SURFACELOST)
pBBuf->Restore();
pBBuf->GetDC(&hdc);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(0,255,0));
sprintf(temp,"score:%6d point",enemylost*50);
TextOut(hdc,backwidth/2-50,70,temp,strlen(temp));
//击落敌机数
sprintf(temp, "x%d", enemylost);
TextOut(hdc, backrect.right-35, backrect.bottom-25, temp, strlen(temp));
//帧频率
SetTextColor(hdc, RGB(255,0,0));
sprintf(temp, "%d帧 / 秒",fps);
TextOut(hdc, 70, 70, temp, strlen(temp));
SetTextColor(hdc,preColor);
pBBuf->ReleaseDC(hdc);
}
if(gamestate==OVER)
{
pBBuf->GetDC(&hdc);
SetBkMode(hdc,  TRANSPARENT);
SetTextColor(hdc,RGB(0,255,0));
sprintf(temp, "shot down %d enemys in all", enemylost);
TextOut(hdc, backwidth/2-40, backheight/2-80, "Game Over", 10);
TextOut(hdc, backwidth/2-55, backheight/2-30, temp, strlen(temp));
TextOut(hdc, backwidth/2-50, backheight/2, "press enter to start ", 21);
      SetTextColor(hdc,preColor);
pBBuf->ReleaseDC(hdc);
}
}void UpdateFrame()
{
if(GetAsyncKeyState(VK_NUMPAD5)&& gamestate==START&&myplane.cancontrol==true)
{
static int nt,ot=GetTickCount();//only run once
nt=GetTickCount();
if(nt>ot+100)
{
ot=nt;
myplane.leftbulletpos[myplane.bullet].x=myplane.position.x+13;
myplane.leftbulletpos[myplane.bullet].y=myplane.position.y;
myplane.rightbulletpos[myplane.bullet].x=myplane.position.x+32;
myplane.rightbulletpos[myplane.bullet].y=myplane.position.y;
myplane.bullet++;
if(myplane.bullet==BULLETNUM)
myplane.bullet=0;
}
}
DrawMap();
CheckHit();
DrawEnemy();
DrawBullet();
DrawPlane();
DrawFlame();
DrawText();
Flip();
}void DrawBullet()
{
for(int i=0;i<BULLETNUM;i++)
{
RECT rectleft,rectright;
rectleft.left=myplane.leftbulletpos[i].x;
rectleft.top=myplane.leftbulletpos[i].y;
rectleft.right=rectleft.left+5;
rectleft.bottom=rectleft.top+13;
rectright.left=myplane.rightbulletpos[i].x;
rectright.top=myplane.rightbulletpos[i].y;
rectright.right=rectright.left+5;
rectright.bottom=rectright.top+13; result=pBBuf->Blt(&rectleft,pOPlaBullet[0],NULL,DDBLT_WAIT|DDBLT_KEYSRC , NULL);
if(result==DDERR_SURFACELOST)
pBBuf->Restore();
result=pBBuf->Blt(&rectright,pOPlaBullet[1],NULL,DDBLT_WAIT|DDBLT_KEYSRC , NULL);
if(result==DDERR_SURFACELOST)
pBBuf->Restore();
myplane.leftbulletpos[i].x--;
myplane.leftbulletpos[i].y-=12;
myplane.rightbulletpos[i].x++;
myplane.rightbulletpos[i].y-=12;
}
}
//
void DrawEnemy()
{
RECT rect;
for(int i=0;i<ENEMYNUM;i++)
{
if(enemy[i].dead!=0)
{
switch(enemy[i].type)
{
case 0://enemy plane
GetRect(&rect,enemy[i].position.x,enemy[i].position.y,35,35);
result=pBBuf->Blt(&rect,pOPlaEnemy,NULL,DDBLT_WAIT|DDBLT_KEYSRC,NULL);
if(result ==DDERR_SURFACELOST)
pBBuf->Restore();
enemy[i].position.x+=enemy[i].way;
enemy[i].position.y+=enemy[i].speed+(myplane.speed-2);
case 1:
GetRect(&rect,enemy[i].position.x,enemy[i].position.y,8,8);
result=pBBuf->Blt(&rect,pOPlaBall,NULL,DDBLT_WAIT|DDBLT_KEYSRC ,NULL);
if(result == DDERR_SURFACELOST)
pBBuf->Restore();
enemy[i].position.x+=enemy[i].way;
enemy[i].position.y+=enemy[i].speed+myplane.speed-2  ;
break;
}
}
if(enemy[i].position.y>backrect.bottom||enemy[i].dead==0)
{
enemy[i].position.x=(int)(forewidth*((long)rand()/32767.0))+35;
enemy[i].position.y=(int)(35*((long)rand()/32767.0));
enemy[i].speed=(int)(4*((long)rand()/32767.0))+1;
enemy[i].way=(int)(3*((long)rand()/32767.0))-1;
enemy[i].type=(int)(2*((long)rand()/32767.0));
enemy[i].dead=1;
}
}
}