📄 winmain.cpp
字号:
{
case 0:
delayshoot = 100;
break;
case 1:
delayshoot = 10;
break;
case 2:
delayshoot = 70;
break;
}
if (bShoot == TRUE)
{
pUFO->Move(iShipPos);
}
else
pUFO->Move(NULL);
pUFO->Draw(lpBackBuffer,lpUfo,NULL);
if (CheckHit(pUFO) == TRUE)
{
pUFO->SetState(1);
score += 10;
//SndObjStop(hsoBoom);
SndObjPlay(hsoBoom,0);
}
if ( (GetTickCount() - pUFO->dwLastShoot) > delayshoot)
{
if (rand()%SHOOTCHANCE == 0)
{
pUFO->dwLastShoot = GetTickCount();
pNewBullet = new Bullet;
if (pBullet == NULL)
{
pBullet = pNewBullet;
pNewBullet->SetType(1);
pNewBullet->SetXY(pUFO->GetX()+24, pUFO->GetY()+50);
}
else
{
pFirstBullet = pBullet;
while (pBullet->GetNext() != NULL)
pBullet = pBullet->GetNext();
pBullet->SetNext(pNewBullet);
pNewBullet->SetPrev(pBullet);
pNewBullet->SetXY(pUFO->GetX()+24, pUFO->GetY()+50);
pNewBullet->SetType(1);
pBullet = pFirstBullet;
}
//SndObjStop(hsoUfoShoot);
SndObjPlay(hsoUfoShoot,0);
}
}
break;
case TRUE:
if (pUFO->DestroyMe() == TRUE)
{
if (pPrev != NULL)
pPrev->SetNext(pUFO->GetNext());
pNext = pUFO->GetNext();
if (pUFO == pFirst)
pFirst=pUFO->GetNext();
//iRepaint = 1;
//pUFO->Repaint(lpBackBuffer, lpBkGround, 1);
delete(pUFO);
if (pPrev != NULL)
pUFO = pPrev;
else
pUFO = pFirst;
break;
}
else
{
pUFO->Draw(lpBackBuffer,lpBoom,0);
if (pUFO->DropExtra() == TRUE)
{
pNewExtra = new Extra;
if (pExtra == NULL)
{
pExtra = pNewExtra;
pNewExtra->SetXY(pUFO->GetX()+22, pUFO->GetY()+20);
pNewExtra->SetType(pUFO->GetExtra());
}
else
{
pFirstExtra = pExtra;
while (pExtra->GetNext() != NULL)
pExtra = pExtra->GetNext();
pExtra->SetNext(pNewExtra);
pNewExtra->SetPrev(pExtra);
pNewExtra->SetXY(pUFO->GetX()+22, pUFO->GetY()+20);
pNewExtra->SetType(pUFO->GetExtra());
pExtra = pFirstExtra;
}
}
}
break;
}
pPrev = pUFO;
if (pUFO != NULL)
pUFO = pUFO->GetNext();
} //** While UFO-NEXT;
pUFO = pFirst;
pAux = pUFO;
while(pAux != NULL)
{
if (CheckCrash(pAux) == TRUE)
pAux->Crash();
pAux = pAux->GetNext();
};
pUFO = pFirst;
}
void bltText(char* buffer, int x, int y)
{
// Draw text to the screen
int pos;
int nextx;
RECT rcRect;
HRESULT hRet;
nextx = x;
while (*buffer != '\0')
{
if (*buffer != ' ')
{
if (*buffer >= 48 &&
*buffer <= 57)
pos = (int) *buffer - 48;
else
pos = (int) *buffer - 55;
if (*buffer == '@')
pos = 36;
if (*buffer == '-')
pos = 37;
if (*buffer == ',')
pos = 38;
if (*buffer == '.')
pos = 39;
rcRect.left = AA[pos].start;
rcRect.right = AA[pos].end;
rcRect.top = 0;
rcRect.bottom = 15;
while (1)
{
hRet = lpBackBuffer->BltFast(nextx, y, lpAlpha, &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
while (1)
{
hRet = lpFrontBuffer->BltFast(nextx, y, lpAlpha, &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
nextx += (AA[pos].end - AA[pos].start) + 1;
}
else
nextx += 15;
buffer++;
}
}
void DrawScore(int x, int y)
{
char scorebuf[9];
unsigned int rem;
// blt everything in reverse order if we are doing destination transparency
// calculate score string
scorebuf[0] = score/10000000 + '0';
rem = score % 10000000;
scorebuf[1] = rem/1000000 + '0';
rem = score % 1000000;
scorebuf[2] = rem/100000 + '0';
rem = score % 100000;
scorebuf[3] = rem/10000 + '0';
rem = score % 10000;
scorebuf[4] = rem/1000 + '0';
rem = score % 1000;
scorebuf[5] = rem/100 + '0';
rem = score % 100;
scorebuf[6] = rem/10 + '0';
rem = score % 10;
scorebuf[7] = rem + '0';
scorebuf[8] = '\0';
bltText(scorebuf, x, y);
}
void DrawShield()
{
// Draw the shield status
HRESULT hRet;
DDBLTFX ddbltfx;
RECT rcRect;
static int iRed = 0;
static int inc = 1;
static DWORD lastBlitRed = 0;
ddbltfx.dwSize = sizeof( ddbltfx );
ddbltfx.dwFillColor = RGB(0,0,0);
rcRect.top = 459;
rcRect.left = 370;
rcRect.bottom = 477;
rcRect.right = 422;
if (iLastShield == iShield &&
iShield > 30)
return;
while (1)
{
hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
if (iLastShield != iShield &&
iShield > 30)
while (1)
{
hRet = lpFrontBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
if (iShield <= 50 &&
iShield > 30)
{
iRed = -2;
lastBlitRed = 0;
ddbltfx.dwFillColor = RGB(0,15,0);
}
if (iShield <= 30 &&
iShield > 20)
ddbltfx.dwFillColor = RGB(0,255,255);
if (iShield <= 20 &&
iShield >= 0)
{
if (GetTickCount() - lastBlitRed > 30)
{
iRed += inc;
if (iRed < 32)
{
iRed = 32;
inc = 4;
}
if (iRed > 116)
{
iRed = 116;
inc = -4;
}
lastBlitRed = GetTickCount();
}
ddbltfx.dwFillColor = RGB(0,iRed,0);
}
rcRect.top = 460;
rcRect.left = 371;
rcRect.bottom = 477;
rcRect.right = 371 + iShield;
while (1)
{
hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
if (iLastShield != iShield &&
iShield > 30)
while (1)
{
hRet = lpFrontBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
iLastShield = iShield;
}
void DrawAmmo()
{
char ammobuf[4];
unsigned int rem;
int iAmmo;
// blt everything in reverse order if we are doing destination transparency
// calculate score string
if (iWeapon < 3)
iAmmo = iLaserAmmo;
else
iAmmo = iPhotonAmmo;
ammobuf[0] = iAmmo/100 + '0';
rem = iAmmo % 100;
ammobuf[1] = rem/10 + '0';
rem = iAmmo % 10;
ammobuf[2] = rem + '0';
ammobuf[3] = '\0';
OutputDebugString("Blit Ammo Buff\n");
bltText(ammobuf, 241, 460);
}
void DrawWeapon()
{
RECT rcRect;
HRESULT hRet;
// Draw the weapon we are using
rcRect.left = iWeapon * 87;
rcRect.right = (iWeapon * 87) + 87;
rcRect.top = 0;
rcRect.bottom = 20;
while (1)
{
hRet = lpBackBuffer->BltFast(84, 458, lpStatusBar, &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
while (1)
{
hRet = lpFrontBuffer->BltFast(84, 458, lpStatusBar, &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
void UpdateFrame( void )
{
int ddrval;
DWORD thisTickCount;
RECT rcRect;
DWORD delay = 18;
static int frame = 0;
HBITMAP hbm;
DDBLTFX ddbltfx;
HRESULT hRet;
thisTickCount = GetTickCount();
// Main update function
if (thisTickCount - dwShipExplode > 2000 &&
iShipState == 3)
{
Ovni* auxpUFO;
Bullet* auxpBullet;
while(pUFO !=NULL)
{
auxpUFO = pUFO->GetNext();
delete(pUFO);
pUFO = auxpUFO;
}
while(pBullet !=NULL)
{
auxpBullet = pBullet->GetNext();
delete(pBullet);
pBullet = auxpBullet;
}
ShowGameOver();
lastTickCount = 0;
iAppState = 0;
iShipState = 0;
}
switch (iAppState)
{
case APP_MAINMENU:
if ((thisTickCount - lastTickCount) <= delay)
return;
if (lastTickCount == 0)
{
iOption = 0;
frame = 0;
hbm = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_INVASION), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION );
if( NULL == hbm )
return;
ddrval = DDCopyBitmap(lpFrontBuffer, hbm, 0, 0, 640, 480 );
if( ddrval != DD_OK )
{
DeleteObject( hbm );
return;
}
ddrval = DDCopyBitmap(lpBackBuffer, hbm, 0, 0, 640, 480 );
if( ddrval != DD_OK )
{
DeleteObject( hbm );
return;
}
bltText("START GAME\0",190,280);
bltText("CREDITS\0",190,320);
bltText("HELP\0",190,360);
bltText("QUIT\0",190,400);
}
ddbltfx.dwSize = sizeof( ddbltfx );
ddbltfx.dwFillColor = dwFillColor;
rcRect.left = 130;
rcRect.top = 270;
rcRect.right = 190;
rcRect.bottom = 460;
while (1)
{
hRet = lpBackBuffer->Blt(&rcRect, NULL, NULL, DDBLT_COLORFILL, &ddbltfx);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
rcRect.left = frame * 32;
rcRect.right = (frame * 32) + 32;
rcRect.top = 0;
rcRect.bottom = 20;
while (1)
{
hRet = lpBackBuffer->BltFast(150 , 275+ (40 * iOption), lpSelect, &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
frame++;
if (frame > 19)
frame = 0;
while( 1 )
{
ddrval = lpFrontBuffer->Flip(NULL, 0 );
if( ddrval == DD_OK )
{
break;
}
if( ddrval == DDERR_SURFACELOST )
{
if( !RestoreSurfaces() )
{
return;
}
}
if( ddrval != DDERR_WASSTILLDRAWING )
{
break;
}
}
lastTickCount = thisTickCount;
return;
case APP_GAMESCREEN:
int iAmmo;
if (lastTickCount == 0)
{
bShoot = FALSE;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = 640;
rcRect.bottom = 480;
DrawBackGround(lpBackBuffer,0,455,640,480);
DrawBackGround(lpFrontBuffer,0,455,640,480);
}
DrawShield();
if (Lastscore != score)
{
DrawBackGround(lpBackBuffer,510,460,640,477);
DrawBackGround(lpFrontBuffer,510,460,640,477);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -