📄 gameengine.cpp
字号:
{
point.x+=screenmovex;
point.y+=screenmovey;
}
DrawTankp(point,rcRect);
}
}
}
//-----------------------------------------------------------------------------
//
// Name: CWALL
// Disc: the member function of the class of the WALL
//-----------------------------------------------------------------------------
void InitWall()
{
GetViewWall();
}
void GetViewWall()
{
for(i=0;i<MAP_WALL_ROW_MAX;i++)
for(j=0;j<MAP_WALL_COL_MAX;j++)
{
POINT point={j*WALL_HEIGHT,i*WALL_WIDTH+40};
switch(rand()%15)
{
case WALL_TYPE_1:
Wall[i][j].SetWall(point,WALL_TYPE_1);
break;
case WALL_TYPE_2:
Wall[i][j].SetWall(point,WALL_TYPE_2);
break;
case WALL_TYPE_3:
Wall[i][j].SetWall(point,WALL_TYPE_3);
break;
case WALL_TYPE_4:
Wall[i][j].SetWall(point,WALL_TYPE_4);
break;
case WALL_TYPE_5:
Wall[i][j].SetWall(point,WALL_TYPE_5);
break;
case WALL_TYPE_6:
Wall[i][j].SetWall(point,WALL_TYPE_6);
break;
case WALL_TYPE_7:
Wall[i][j].SetWall(point,WALL_TYPE_7);
break;
case WALL_TYPE_8:
Wall[i][j].SetWall(point,WALL_TYPE_8);
break;
default:
Wall[i][j].SetNowPos(point.x,point.y);
Wall[i][j].SetLifeState(FALSE);
Wall[i][j].SetWallState(FALSE);
break;
}
}
}
void DrawWall(int x,int y,int type)
{
HRESULT hRet;
RECT rcRect;
rcRect.top=0;
rcRect.left=0;
rcRect.bottom=80;
rcRect.right=80;
// Draw the ship sprite
while (1)
{
hRet = lpBackBuffer->BltFast(x+screenmovex,y+screenmovey, lpWall[type], &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
BOOL IsOverBoundry(int m,int n)
{
int x=Tank[m][n].GetNowPos().x-screenmovex;
int y=Tank[m][n].GetNowPos().y-screenmovey;
int speed=Tank[m][n].GetSpeed();
BOOL result=CheckViewBoundry(x,y);
if(result)
{
switch(Tank[m][n].GetMDirection())
{
case TANK_MOVE_UP:
if(x-speed>Wall[0][0].GetWallPos().x)
return TANK_MOVE_UP;
break;
case TANK_MOVE_DOWN:
if(x+speed>Wall[0][0].GetWallPos().x)
return TANK_MOVE_DOWN;
break;
case TANK_MOVE_LEFT:
if(y-speed>Wall[0][0].GetWallPos().x)
return TANK_MOVE_LEFT;
break;
case TANK_MOVE_RIGHT:
if(y+speed>Wall[0][0].GetWallPos().x)
return TANK_MOVE_RIGHT;
break;
}
}
return -1;
}
BOOL CheckViewBoundry(int x,int y)
{
BOOL movable=TRUE;
if(x<0)
movable=FALSE;
if(y<=40)
movable=FALSE;
if(x>=1024)
movable=FALSE;
if(y>=700)
movable=FALSE;
return movable;
}
int GetScreenXRemove(int x)
{
return x/WALL_WIDTH;
}
int GetScreenYRemove(int y)
{
return y/WALL_HEIGHT;
}
void DrawMap()
{
int n=GetScreenXRemove((int)fabs(screenmovex));
int m=GetScreenYRemove((int)fabs(screenmovey));
for(i=m;i<MAP_WALL_ROW_VIEW+m;i++)
for(j=n;j<MAP_WALL_COL_VIEW+n;j++)
{
if(Wall[i][j].IsVisible())
DrawWall(Wall[i][j].GetWallPos().x,Wall[i][j].GetWallPos().y,Wall[i][j].GetType());
}
}
void DrawSmallMap()
{
// 864,42,140,100
HRESULT hRet;
RECT rect;
for(int m=0;m<TANK_WAR_SIDE;m++)
for(int n=0;n<TANK_TOTAL_NUMBER;n++)
{
if(!(m==0&&n>iPlayerModel)&&Tank[m][n].IsLivable())
{
int x=864+(int)((float)(Tank[m][n].GetNowPos().x+((m==0)? -screenmovex:0))*0.04166);
int y=660+(int)((float)(Tank[m][n].GetNowPos().y+((m==0)? -screenmovey:0))*0.04762);
rect.top=((m==0)? 0:20);
rect.left=112;
rect.bottom=rect.top+20;
rect.right=132;
while (1)
{
hRet = lpBackBuffer->BltFast(x,y, lpTank, &rect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
}
}
void DrawSmallWindow()
{
// 864,42,140,100
HRESULT hRet;
RECT rect;
int x=864+(int)((float)(-screenmovex)*0.04166);
int y=660+(int)((float)(-screenmovey)*0.04762);
rect.top=46;
rect.left=114;
rect.bottom=97;
rect.right=171;
while (1)
{
hRet = lpBackBuffer->BltFast(x,y, lpTank, &rect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
//-----------------------------------------------------------------------------
//
// Name: CWALL
// Disc: the member function of the class of the WALL
//-----------------------------------------------------------------------------
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 DrawInformation()
{
iLevel=Level.GetGameLevel();
bltText(NumToChar(score),46,667);
bltText(NumToChar(Tank[0][0].GetLifeTimes()),46,712);
bltText(NumToChar(iLevel),123,712);
iTankNum=CountEnemyTank();
bltText(NumToChar(iTankNum),520,690);
bltText(NumToChar(Tank[0][0].GetLifecount()),520,716);
bltText(NumToChar(Tank[0][0].GetPower()),520,740);
}
//-----------------------------------------------------------------
//
// Name: score
// Instruction: member fuctions on score
//
//-----------------------------------------------------------------
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);
}
//-----------------------------------------------------------------
//
// Name: DrawShield
// Instruction: member fuctions on DrawShield
//
//-----------------------------------------------------------------
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;
}
//-----------------------------------------------------------------
//
// Name: DrawStatusBar
// Instruction: member fuctions on DrawStatusbBar
//
//-----------------------------------------------------------------
void DrawStatusBar()
{
RECT rcRect;
HRESULT hRet;
// Draw the weapon we are using
rcRect.left = 0;
rcRect.right = 1024;
rcRect.top = 0;
rcRect.bottom = 151;
while (1)
{
hRet = lpBackBuffer->BltFast(0, 617, lpStatusBar, &rcRect, TRUE);
if (hRet == DD_OK)
{
break;
}
if (hRet == DDERR_SURFACELOST)
{
hRet = RestoreSurfaces();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
//-----------------------------------------------------------------
//
// Name: DrawPowerBar
// Instruction: member fuctions on DrawShield
//
//-----------------------------------------------------------------
void DrawPowerBar()
{
RECT rcRect;
H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -