接前一个贴的下一段代码
bool InitDDraw()
{
//DWORD dwFlags;
DDSURFACEDESC2 desc; result=DirectDrawCreateEx(NULL,(VOID**)&pDD7,IID_IDirectDraw7,NULL);
if(result!=DD_OK)
MessageBox(hWnd,"create directdraw object failed","error",MB_OK);
DWORD dwFlags=DDSCL_NORMAL;
result=pDD7->SetCooperativeLevel(hWnd,dwFlags);
if(result!=DD_OK)
MessageBox(hWnd,"setcooperativelevel failed","error",MB_OK);
//primary
memset(&desc,0,sizeof(desc));
desc.dwSize=sizeof(desc);
desc.dwFlags=DDSD_CAPS;//|DDSD_BACKBUFFERCOUNT;
//desc.dwBackBufferCount=1;
desc.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE;//|DDSCAPS_FLIP;
result=pDD7->CreateSurface(&desc,&pPSur,NULL);
if(result!=DD_OK)
MessageBox(hWnd,"Create primary surface failed","error",MB_OK);
//back
desc.dwAlphaBitDepth=DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
desc.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN;
RECT rect;
::GetClientRect(hWnd,&rect);
forewidth=rect.right-rect.left;
foreheight=rect.bottom-rect.top;
GetRect(&backrect,65,65, forewidth, foreheight);
desc.dwWidth=backwidth=forewidth+130;
desc.dwHeight=backheight=foreheight+130;
pDD7->CreateSurface(&desc,&pBBuf,NULL);
//pPSur->GetAttachedSurface(&desc.ddsCaps,&pBBuf);
//map
result=CreateBMP(700,640, "cloud.bmp",pOPlaMap);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//plane
result=CreateBMP(50,60,"left.bmp",pOPlaPlane[0]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
result=CreateBMP(50,60,"center.bmp",pOPlaPlane[1]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
result=CreateBMP(50,60,"right.bmp",pOPlaPlane[2]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
// bomb
result=CreateBMP(14,36,"bom1.bmp",pOPlaBomb);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//enemy
result=CreateBMP(35,35,"enemy.bmp",pOPlaEnemy);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//flame
result=CreateBMP(540,50,"flame.bmp",pOPlaFlame);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//myplane dead flame
result=CreateBMP(528,66,"flamedead.bmp",pOPlaDead);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//enemy bullet
result=CreateBMP(8,8,"ball.bmp",pOPlaBall);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//myplane bullet
result=CreateBMP(5,13,"bullet0.bmp",pOPlaBullet[0]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
result=CreateBMP(5,13,"bullet1.bmp",pOPlaBullet[1]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//clipper
// pDD7->CreateClipper(0,&pClipper,NULL);
// pClipper->SetHWnd(0,hWnd);
//pPSur->SetClipper(pClipper);
//get current path
_getcwd(midipath,sizeof(midipath));
strcpy(openmidi,"play");
strcat(openmidi,midipath);
strcat(openmidi,"\\a.mid");
strcpy(closemidi,"close");
strcat(closemidi,midipath);
strcat(closemidi,"\\a.mid");
char buf[256];
mciSendString(openmidi,buf,sizeof(buf),NULL);
//GAME INIT
for(int i=0;i<ENEMYNUM;i++)
enemy[i].dead=0;
gamestate=INIT;
return true;
}void FreeDDraw()
{
if(pDD7!=NULL)
{
if(pPSur!=NULL)
{
pPSur->Release();
pPSur=NULL;
}
if(pBBuf!=NULL)
{
pBBuf->Release();
pBBuf=NULL;
}
for (int i=0 ;i<3; i++)
{
if(pOPlaPlane[i]!=NULL)
{
pOPlaPlane[i]->Release();
pOPlaPlane[i]=NULL;
}
}
if(pOPlaBomb!=NULL)
{
pOPlaBomb->Release();
pOPlaBomb=NULL;
}
for (i=0 ;i<2; i++)
{
if(pOPlaBullet[i]!=NULL)
{
pOPlaBullet[i]->Release();
pOPlaBullet[i]=NULL;
}
}
if(pOPlaMap!=NULL)
{
pOPlaMap->Release();
pOPlaMap=NULL;
}
if(pOPlaFlame!=NULL)
{
pOPlaFlame->Release();
pOPlaFlame=NULL;
}
if(pOPlaEnemy!=NULL)
{
pOPlaEnemy->Release();
pOPlaEnemy=NULL;
}
if( pOPlaDead != NULL )
{
pOPlaDead->Release(); pOPlaDead = NULL;
}
if( pOPlaBall != NULL )
{
pOPlaBall->Release(); pOPlaBall = NULL;
}
pDD7->Release();
pDD7 = NULL;
}
}
bool InitDDraw()
{
//DWORD dwFlags;
DDSURFACEDESC2 desc; result=DirectDrawCreateEx(NULL,(VOID**)&pDD7,IID_IDirectDraw7,NULL);
if(result!=DD_OK)
MessageBox(hWnd,"create directdraw object failed","error",MB_OK);
DWORD dwFlags=DDSCL_NORMAL;
result=pDD7->SetCooperativeLevel(hWnd,dwFlags);
if(result!=DD_OK)
MessageBox(hWnd,"setcooperativelevel failed","error",MB_OK);
//primary
memset(&desc,0,sizeof(desc));
desc.dwSize=sizeof(desc);
desc.dwFlags=DDSD_CAPS;//|DDSD_BACKBUFFERCOUNT;
//desc.dwBackBufferCount=1;
desc.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE;//|DDSCAPS_FLIP;
result=pDD7->CreateSurface(&desc,&pPSur,NULL);
if(result!=DD_OK)
MessageBox(hWnd,"Create primary surface failed","error",MB_OK);
//back
desc.dwAlphaBitDepth=DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
desc.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN;
RECT rect;
::GetClientRect(hWnd,&rect);
forewidth=rect.right-rect.left;
foreheight=rect.bottom-rect.top;
GetRect(&backrect,65,65, forewidth, foreheight);
desc.dwWidth=backwidth=forewidth+130;
desc.dwHeight=backheight=foreheight+130;
pDD7->CreateSurface(&desc,&pBBuf,NULL);
//pPSur->GetAttachedSurface(&desc.ddsCaps,&pBBuf);
//map
result=CreateBMP(700,640, "cloud.bmp",pOPlaMap);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//plane
result=CreateBMP(50,60,"left.bmp",pOPlaPlane[0]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
result=CreateBMP(50,60,"center.bmp",pOPlaPlane[1]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
result=CreateBMP(50,60,"right.bmp",pOPlaPlane[2]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
// bomb
result=CreateBMP(14,36,"bom1.bmp",pOPlaBomb);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//enemy
result=CreateBMP(35,35,"enemy.bmp",pOPlaEnemy);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//flame
result=CreateBMP(540,50,"flame.bmp",pOPlaFlame);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//myplane dead flame
result=CreateBMP(528,66,"flamedead.bmp",pOPlaDead);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//enemy bullet
result=CreateBMP(8,8,"ball.bmp",pOPlaBall);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//myplane bullet
result=CreateBMP(5,13,"bullet0.bmp",pOPlaBullet[0]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
result=CreateBMP(5,13,"bullet1.bmp",pOPlaBullet[1]);
if(result != DD_OK)
MessageBox(hWnd,"load map failed","error",MB_OK);
//clipper
// pDD7->CreateClipper(0,&pClipper,NULL);
// pClipper->SetHWnd(0,hWnd);
//pPSur->SetClipper(pClipper);
//get current path
_getcwd(midipath,sizeof(midipath));
strcpy(openmidi,"play");
strcat(openmidi,midipath);
strcat(openmidi,"\\a.mid");
strcpy(closemidi,"close");
strcat(closemidi,midipath);
strcat(closemidi,"\\a.mid");
char buf[256];
mciSendString(openmidi,buf,sizeof(buf),NULL);
//GAME INIT
for(int i=0;i<ENEMYNUM;i++)
enemy[i].dead=0;
gamestate=INIT;
return true;
}void FreeDDraw()
{
if(pDD7!=NULL)
{
if(pPSur!=NULL)
{
pPSur->Release();
pPSur=NULL;
}
if(pBBuf!=NULL)
{
pBBuf->Release();
pBBuf=NULL;
}
for (int i=0 ;i<3; i++)
{
if(pOPlaPlane[i]!=NULL)
{
pOPlaPlane[i]->Release();
pOPlaPlane[i]=NULL;
}
}
if(pOPlaBomb!=NULL)
{
pOPlaBomb->Release();
pOPlaBomb=NULL;
}
for (i=0 ;i<2; i++)
{
if(pOPlaBullet[i]!=NULL)
{
pOPlaBullet[i]->Release();
pOPlaBullet[i]=NULL;
}
}
if(pOPlaMap!=NULL)
{
pOPlaMap->Release();
pOPlaMap=NULL;
}
if(pOPlaFlame!=NULL)
{
pOPlaFlame->Release();
pOPlaFlame=NULL;
}
if(pOPlaEnemy!=NULL)
{
pOPlaEnemy->Release();
pOPlaEnemy=NULL;
}
if( pOPlaDead != NULL )
{
pOPlaDead->Release(); pOPlaDead = NULL;
}
if( pOPlaBall != NULL )
{
pOPlaBall->Release(); pOPlaBall = NULL;
}
pDD7->Release();
pDD7 = NULL;
}
}
将程序发到:[email protected]我看看