?? bonus.cpp
字號:
// Bonus.cpp: implementation of the CBonus class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Bonus.h"
#include "MainGame.h"
#include "BigBomb.h"
extern int score1,score2;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//class CPlayerTank;
CBonus::CBonus():CContainerObject(this)
{
type=rand()%11+20; //為了避免和坦克同類型
positionX=rand()%40*16;
positionY=rand()%30*16;
width=32;
height=32;
eat=0;
count=0;
temp=CContainerObject::pFirst;
}
CBonus::~CBonus()
{
}
/*
void CBonus::ChangeStone()
{
int i,j;
Map[13][9]=Map[13][10]=Map[14][9]=Map[14][10]=1;
for(i=13*4+2;i<15*4;i++)
for(j=9*4;j<11*4;j++)GameMap[i][j]=1;
for(i=14*4;i<15*4;i++)
for(j=9*4+2;j<11*4-2;j++)GameMap[i][j]=5;
return;
}
*/
void CBonus::displayObject()
{
CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
CRect rt1(positionX,positionY,positionX+width,positionY+height);
CRect rt2(0,(type-20)*32,32,(type+1-20)*32);
pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[16],rt2);
}
bool CBonus::ActiveObject()
{
CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
if(!eat)
{
temp=CContainerObject::pFirst;
while(temp)
{
if(strcmp(temp->name,"PlayerTank")==0) //自己人才能吃
{
if(abs(positionX-temp->positionX)<=16 &&
abs(positionY-temp->positionY)<=16)
{
eat = 1; //吃到了
sndPlaySound("sound//bonus.wav",SND_ASYNC|SND_NODEFAULT);
return true;
}
else temp=temp->pNext;
}
else temp=temp->pNext;
}
CBonus::displayObject();
return true;
}
else
{
switch(type-20)
{
case 0:
{
if(temp->type<4)
{
pWnd->playerTank2->GetAttack();
return false;
}
else
{
pWnd->playerTank1->GetAttack();
return false;
}
}break;
case 1:
{
temp=CContainerObject::pFirst;
while(temp)
{
if(strcmp(temp->name,"EnemyTank")==0)
{
temp->movement=0;
temp=temp->pNext;
}
else temp=temp->pNext;
}
}break;
case 2:
{
if(temp->type<4)
{
pWnd->player2++;
return false;
}
else
{
pWnd->player1++;
return false;
}
}break;
case 3:
{
if(temp->type<4)
{
pWnd->playerTank2->GetSpeed();
}
else
{
pWnd->playerTank1->GetSpeed();
}
}break;
case 4:
{
if(temp->type<4)
{
pWnd->playerTank2->fireType=2;
}
else
{
pWnd->playerTank1->fireType=2;
}
}break;
case 5:
{
CBigBomb *bomb=new CBigBomb;
KillAllEnemyTank();
return false;
}break;
case 6:
{
pWnd->theMap->GetDefend(1);
}break;
case 7:
{
if(temp->type<4)score2+=500;
else score1+=500;
return false;
}
case 8:
{
if(temp->type<4)score2+=200;
else score1+=200;
return false;
}
case 9:
{
if(temp->type<4)score2+=100;
else score1+=100;
return false;
}
}
}
if(count>1000) //恢復
{
switch(type-20)
{
case 1:
{
temp=CContainerObject::pFirst;
while(temp)
{
if(strcmp(temp->name,"EnemyTank")==0)
{
temp->movement=1;
temp=temp->pNext;
}
else temp=temp->pNext;
}
}break;
case 3:
{
if(pWnd->playerTank2->speed==2)
pWnd->playerTank2->speed--;
if(pWnd->playerTank1->speed==2)
pWnd->playerTank1->speed--;
}break;
case 4:
{
pWnd->playerTank1->fireType=1;
pWnd->playerTank2->fireType=1;
}break;
case 6:
{
pWnd->theMap->GetDefend(3);
}
}//switch
return false;
}
else
{
count++;
return true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -