📄 bubbleiidlg.cpp
字号:
CString s;
s.Format("%d,",nKey);
TRACE(s);
int i=0;
switch(nKey)
{
case 65:
case 87:
case 83:
case 68:
if(m_U1key[0]==0 && m_U1key[1]!=nKey)
{
m_U1key[0]=nKey;
HandleKeyin(nKey);
}
else
{
if(m_U1key[0]!=nKey && m_U1key[1]==0)
{
m_U1key[1]=nKey;
HandleKeyin(nKey);
}
}
break;
case 37:
case 38:
case 39:
case 40:
if(m_U2key[0]==0 && m_U2key[1]!=nKey)
{
m_U2key[0]=nKey;
HandleKeyin(nKey);
}
else
{
if(m_U2key[0]!=nKey && m_U2key[1]==0)
{
m_U2key[1]=nKey;
HandleKeyin(nKey);
}
}
break;
case 13:
if((GLB::pGhostThread[29]->m_bSetBubbleNotLeave)==FALSE)
{
//if(!GLB::pGhostThread[29]->m
for(i=0; i<GLB::pGhostThread[29]->m_iBubbleNum; i++)
{
if(GLB::pBubbleThread[i]->m_state==DEAD)
{
::PlaySound("SOUND\\SETBUBBLE.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
GLB::pBubbleThread[i]->SetBubble(
i,29,
((int)(GLB::pGhostThread[29]->m_x+GLB::iBlockWidth/2))/GLB::iBlockWidth*GLB::iBlockWidth,
((int)(GLB::pGhostThread[29]->m_y+GLB::iBlockHeight/2))/GLB::iBlockHeight*GLB::iBlockHeight,
GLB::pGhostThread[29]->m_iBubbleRadius,2500
);
GLB::pGhostThread[29]->m_bSetBubbleNotLeave=TRUE;
GLB::pGhostThread[29]->m_iLastBubbleIndex=i;
break;
}
}
}
return TRUE;
case 32:
if((GLB::pGhostThread[28]->m_bSetBubbleNotLeave)==FALSE)
{
for(i=10; i<10+GLB::pGhostThread[28]->m_iBubbleNum; i++)
{
if(GLB::pBubbleThread[i]->m_state==DEAD)
{
::PlaySound("SOUND\\SETBUBBLE.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
GLB::pBubbleThread[i]->SetBubble(
i,28,
((int)(GLB::pGhostThread[28]->m_x+GLB::iBlockWidth/2))/GLB::iBlockWidth*GLB::iBlockWidth,
((int)(GLB::pGhostThread[28]->m_y+GLB::iBlockHeight/2))/GLB::iBlockHeight*GLB::iBlockHeight,
GLB::pGhostThread[28]->m_iBubbleRadius,2500
);
GLB::pGhostThread[28]->m_bSetBubbleNotLeave=TRUE;
GLB::pGhostThread[28]->m_iLastBubbleIndex=i;
break;
}
}
}
break;
default:
break;
}
}
if(pMsg->message == WM_SYSKEYUP || pMsg->message == WM_KEYUP)
{
if(nKey==65||nKey==87||nKey==83||nKey==68)
{
int i=(m_U1key[0]!=0)*0x1000+(m_U1key[0]==nKey)*0x0100+(m_U1key[1]!=0)*0x0010+(m_U1key[1]==nKey);
switch(i)
{
//假如0、1两个都不为0,而且没有相应的键松开:不动作
case 0x1010:
break;
//如果0、1中两个都不为0,且先按的(0)键松开:
case 0x1110:
HandleKeyin(m_U1key[1]);
m_U1key[0]=0;
break;
//如果0、1中两个都不为0,且后按的(1)键松开:
case 0x1011:
HandleKeyin(m_U1key[0]);
m_U1key[1]=0;
break;
//如果0、1中两个只有先按的不为0,且松开的是这个键,则:
case 0x1100:
GLB::pGhostThread[28]->m_iWaittime=20;
GLB::pGhostThread[28]->m_iDirect=5;
m_U1key[0]=0;
break;
//如果0、1中两个只有后按的不为0,且松开的是这个键,则:
case 0x0011:
GLB::pGhostThread[28]->m_iWaittime=20;
GLB::pGhostThread[28]->m_iDirect=5;
m_U1key[1]=0;
break;
default:
break;
}
}
if(nKey>=37 && nKey<=40)
{
CString s;
s.Format("%d,",nKey);
TRACE(s);
int i=(m_U2key[0]!=0)*0x1000+(m_U2key[0]==nKey)*0x0100+(m_U2key[1]!=0)*0x0010+(m_U2key[1]==nKey);
switch(i)
{
//假如0、1两个都不为0,而且没有相应的键松开:不动作
case 0x1010:
break;
//如果0、1中两个都不为0,且先按的(0)键松开:
case 0x1110:
HandleKeyin(m_U2key[1]);
m_U2key[0]=0;
break;
//如果0、1中两个都不为0,且后按的(1)键松开:
case 0x1011:
HandleKeyin(m_U2key[0]);
m_U2key[1]=0;
break;
//如果0、1中两个只有先按的不为0,且松开的是这个键,则:
case 0x1100:
GLB::pGhostThread[29]->m_iWaittime=20;
GLB::pGhostThread[29]->m_iDirect=5;
m_U2key[0]=0;
break;
//如果0、1中两个只有后按的不为0,且松开的是这个键,则:
case 0x0011:
GLB::pGhostThread[29]->m_iWaittime=20;
GLB::pGhostThread[29]->m_iDirect=5;
m_U2key[1]=0;
break;
default:
break;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CBubbleIIDlg::HandleKeyin(UINT nKey)
{
switch(nKey)
{
//"w"
case 87:
GLB::pGhostThread[28]->m_iWaittime=2;
GLB::pGhostThread[28]->m_iDirect=0;
break;
//"a"
case 65:
GLB::pGhostThread[28]->m_iWaittime=2;
GLB::pGhostThread[28]->m_iDirect=1;
break;
//"s"
case 83:
GLB::pGhostThread[28]->m_iWaittime=2;
GLB::pGhostThread[28]->m_iDirect=2;
break;
//"d"
case 68:
GLB::pGhostThread[28]->m_iWaittime=2;
GLB::pGhostThread[28]->m_iDirect=3;
break;
//"↑"
case 38:
GLB::pGhostThread[29]->m_iWaittime=2;
GLB::pGhostThread[29]->m_iDirect=0;
break;
//"←"
case 37:
GLB::pGhostThread[29]->m_iWaittime=2;
GLB::pGhostThread[29]->m_iDirect=1;
break;
//"↓"
case 40:
GLB::pGhostThread[29]->m_iWaittime=2;
GLB::pGhostThread[29]->m_iDirect=2;
break;
//"→"
case 39:
GLB::pGhostThread[29]->m_iWaittime=2;
GLB::pGhostThread[29]->m_iDirect=3;
break;
//"ENTER"
case 13:
return TRUE;
default:
break;
}
return FALSE;
}
void CBubbleIIDlg::OnNewsingle()
{
// TODO: Add your command handler code here
GLB::iGameStage=1;
if(LoadMap())
{
KillTimer(m_iTimer);
GLB::bHeightAlive=FALSE;
GLB::pGhostThread[28]->m_iLifeLeft=4;
GLB::pGhostThread[29]->m_iLifeLeft=0;
SetNPCGhosts();
SetGhostRandPosLegally(GLB::pGhostThread[28],3,5,1.5,2);
GLB::bGameStarted=TRUE;
GLB::eGameType=SINGLEPLAYER;
::PlaySound("SOUND\\CLEAR.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
}
}
void CBubbleIIDlg::OnNewMultifight()
{
// TODO: Add your command handler code here
GLB::iGameStage=1;
if(LoadMap())
{
KillTimer(m_iTimer);
GLB::bHeightAlive=FALSE;
GLB::pGhostThread[28]->m_iLifeLeft=4;
GLB::pGhostThread[29]->m_iLifeLeft=4;
SetNPCGhosts();
SetGhostRandPosLegally(GLB::pGhostThread[28],3,5,1.5,2);
SetGhostRandPosLegally(GLB::pGhostThread[29],3,5,1.5,2);
GLB::bGameStarted=TRUE;
GLB::eGameType=MULTIPLAYERFIGHT;
::PlaySound("SOUND\\CLEAR.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
}
}
void CBubbleIIDlg::OnNewcoop()
{
// TODO: Add your command handler code here
GLB::iGameStage=1;
if(LoadMap())
{
KillTimer(m_iTimer);
GLB::bHeightAlive=FALSE;
GLB::pGhostThread[28]->m_iLifeLeft=4;
GLB::pGhostThread[29]->m_iLifeLeft=4;
SetNPCGhosts();
SetGhostRandPosLegally(GLB::pGhostThread[28],3,5,1.5,2);
SetGhostRandPosLegally(GLB::pGhostThread[29],3,5,1.5,2);
GLB::bGameStarted=TRUE;
GLB::eGameType=MULTIPLAYERCOOP;
::PlaySound("SOUND\\CLEAR.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
}
}
void CBubbleIIDlg::CalcuBackInfo(CBitmap *pBackBMP)
{
HBITMAP hBitmap=(HBITMAP)(*pBackBMP);
tagBITMAP* uBgBMP=(BITMAP *) new BYTE[sizeof(BITMAP)];
::GetObject(hBitmap,sizeof(BITMAP),uBgBMP);
GLB::iBackBMPWidth=uBgBMP->bmWidth;
GLB::iBackBMPHeight=uBgBMP->bmHeight;
if(GLB::iWindowWidth%GLB::iBackBMPWidth==0)
GLB::iBackBMPXNum=GLB::iWindowWidth/GLB::iBackBMPWidth;
else
GLB::iBackBMPXNum=GLB::iWindowWidth/GLB::iBackBMPWidth+1;
if(GLB::iWindowHeight%GLB::iBackBMPHeight==0)
GLB::iBackBMPYNum=GLB::iWindowHeight/GLB::iBackBMPHeight;
else
GLB::iBackBMPYNum=GLB::iWindowHeight/GLB::iBackBMPHeight+1;
delete uBgBMP;
}
void CBubbleIIDlg::SetGhostRandPosLegally(CGhostThread* pGhostThread, int bubblenum, int direct, double speed, int waittime)
{
int iX=0, iY=0, iCont=0;
do
{
iX=((int)(rand()*1.0*GLB::iXBlocks/RAND_MAX));
iY=((int)(rand()*1.0*GLB::iYBlocks/RAND_MAX));
iCont=*(GLB::pIBackMatrix+iY*GLB::iXBlocks+iX);
for(int j=0; j<6; j++)
{
if(abs((int)(iX*GLB::iBlockWidth-GLB::pGhostThread[j]->m_x))<GLB::iBlockWidth &&
abs((int)(iY*GLB::iBlockHeight-GLB::pGhostThread[j]->m_y))<GLB::iBlockHeight)
{
iCont=20;
break;
}
}
}
while(iCont==20 || iCont==30 || iCont==40 || iCont==60);
// int iD=(int)(rand()*1.0/RAND_MAX*4);
// int wt=(int)(rand()*20.0/RAND_MAX);
//[0]到[5]是由电脑控制的,标志是Initiate中的第一个参数。倒数第二个参数wt是
//循环中的延时时间
pGhostThread->SetGhost(bubblenum,iX*(GLB::iBlockWidth),iY*(GLB::iBlockHeight),direct,speed,waittime);
pGhostThread->m_iLifeLeft--;
}
void CBubbleIIDlg::OnTimer(UINT nIDEvent)
{
CDC* pDC=GetDC();
if(nIDEvent == TIMER_START)
{
GLB::pMyWater->Render((DWORD*)m_bmpRenderSource.GetDIBits(),(DWORD*)m_bmpRenderTarget.GetDIBits());
GLB::pMyWater->SineBlob((int)(rand()*600.0/RAND_MAX),(int)(rand()*422.0/RAND_MAX),(int)(rand()*20.0/RAND_MAX),50,GLB::pMyWater->m_iHpage);
CPoint ptOrigin(GLB::iWindowWidth/2-300,GLB::iWindowHeight/2-211);
m_bmpRenderTarget.Draw(pDC,ptOrigin);
GLB::RepaintMemScore();
if(GLB::iRepaintScoreFrameNum%25==0)
{
pDC->BitBlt(0,GLB::iWindowHeight+1,GLB::iWindowWidth,40,GLB::pMemDC,0,GLB::iWindowHeight+1,SRCCOPY);
GLB::iRepaintScoreFrameNum=0;
}
GLB::iRepaintScoreFrameNum++;
}
if(nIDEvent == GAME_TIMER)
{
if((GLB::eGameType!=GAMEOVER) && (GLB::pGhostThread[28]->m_eState==GHOSTDEAD))
{
switch(GLB::eGameType)
{
case SINGLEPLAYER:
if(GLB::pGhostThread[28]->m_iLifeLeft>0)
SetGhostRandPosLegally(GLB::pGhostThread[28],3,5,1.5,2);
else
{
::PlaySound("SOUND\\LOST.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
GLB::eGameType=GAMEOVER;
}
break;
case MULTIPLAYERCOOP:
case MULTIPLAYERFIGHT:
if(GLB::pGhostThread[28]->m_iLifeLeft>0)
SetGhostRandPosLegally(GLB::pGhostThread[28],3,5,1.5,2);
else
{
if((GLB::pGhostThread[29]->m_iLifeLeft<=0)&&(GLB::pGhostThread[29]->m_eState==GHOSTDEAD))
{
::PlaySound("SOUND\\LOST.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
GLB::eGameType=GAMEOVER;
}
}
break;
default:
break;
}
}
if((GLB::eGameType==MULTIPLAYERFIGHT||GLB::eGameType==MULTIPLAYERCOOP) && (GLB::pGhostThread[29]->m_eState==GHOSTDEAD))
{
if(GLB::pGhostThread[29]->m_iLifeLeft>0)
SetGhostRandPosLegally(GLB::pGhostThread[29],3,5,1.5,2);
else
{
if((GLB::pGhostThread[28]->m_iLifeLeft<=0)&&(GLB::pGhostThread[28]->m_eState==GHOSTDEAD))
{
::PlaySound("SOUND\\LOST.WAV",NULL,SND_NODEFAULT|SND_ASYNC);
GLB::eGameType=GAMEOVER;
}
}
}
if(GLB::bStageWin)
{
Sleep(1900);
GLB::iGameStage++;
if(LoadMap())
{
SetNPCGhosts();
}
}
}
CDialog::OnTimer(nIDEvent);
}
void CBubbleIIDlg::SetNPCGhosts()
{
for(int i=0; i<6; i++)
{
SetGhostRandPosLegally(GLB::pGhostThread[i],0,rand()*4/RAND_MAX,2,20);
}
if(!GLB::bRepaintThreadAlive)
{
GLB::bRepaintThreadAlive=TRUE;
AfxBeginThread(Repainter,NULL);
}
}
void CBubbleIIDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(!GLB::bRepaintThreadAlive)
{
point.y = GLB::iWindowHeight/2+211-point.y;
point.x = point.x-GLB::iWindowWidth/2+300;
if(point.y<0)
point.y=0;
if(point.y>422)
point.y=422;
if(point.x<0)
point.x=0;
if(point.x>600)
point.x=600;
// GLB::pMyWater->HeightBlob(point.x ,point.y,3,200,GLB::pMyWater->m_iHpage);
// GLB::pMyWater->Render((DWORD*)m_bmpRenderSource.GetDIBits(),(DWORD*)m_bmpRenderTarget.GetDIBits());
GLB::pMyWater->HeightBlob(point.x,point.y,(int)(rand()*20.0/RAND_MAX),50,GLB::pMyWater->m_iHpage);
}
CDialog::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -