📄 mygame.cpp
字号:
for (itbouns=vbouns.begin();itbouns!=vbouns.end();itbouns++)
{
bouns bounstmp;
bounstmp=*itbouns;
if (bounstmp.status==BOUNS_STATUS_NORMAL)
{
r2.left=bounstmp.Pos.x;
r2.right=r2.left+bounstmp.width;
r2.top=bounstmp.Pos.y;
r2.bottom=r2.top+bounstmp.height;
if (msIsIntersectRect( &r1,&r2 ))
{
if(player1.bulltp==bounstmp.type)
{
if (player1.bullpw<3){player1.bullpw++;}
}
else
{
player1.bulltp=bounstmp.type;
if (player1.bullpw>0){player1.bullpw--;}
}
bounstmp.status=BOUNS_STATUS_DEAD;
}
}
(*itbouns)=bounstmp;
}
for (itpen=planeenemy.begin();itpen!=planeenemy.end();itpen++)
{
Cpenemy tempp;
tempp=*itpen;
r2.left=tempp.PPos.x;
r2.right=r2.left+tempp.width;
r2.top=tempp.PPos.y;
r2.bottom=r2.top+tempp.height;
if ((msIsIntersectRect( &r1,&r2 ))&&(tempp.enemystate!=ENEMY_STATUS_DEAD))
{
int a=player1.health;
player1.health-=tempp.health;
tempp.health-=a;
if (tempp.health<=0)
{
tempp.enemystate=ENEMY_STATUS_DEAD;
if (tempp.enemytype==1)
{
mboom1->Play();
bouns bounstemp(tempp.PPos.x,tempp.PPos.y,15,13,2,2,2);
vbouns.push_back(bounstemp);
xg xgtemp(100,90,tempp.PPos.x,tempp.PPos.y,11,6,0);
vxg.push_back(xgtemp);
}
if (tempp.enemytype==0)
{
xg xgtemp(40,42,tempp.PPos.x,tempp.PPos.y,16,16,4);
vxg.push_back(xgtemp);
mboom2->Play();
}
if (tempp.enemytype==3)
{
xg xgtemp(100,90,tempp.PPos.x,tempp.PPos.y,11,6,0);
vxg.push_back(xgtemp);
mboom3->Play();
}
if (tempp.enemytype==4)
{
xg xgtemp(48,32,tempp.PPos.x+35,tempp.PPos.y,16,8,6);
vxg.push_back(xgtemp);
mboom4->Play();
}
if (tempp.enemytype==5)
{
xg xgtemp(48,32,tempp.PPos.x,tempp.PPos.y,16,8,6);
vxg.push_back(xgtemp);
mboom1->Play();
}
if (tempp.enemytype==6)
{
xg xgtemp(100,90,tempp.PPos.x,tempp.PPos.y,11,6,0);
vxg.push_back(xgtemp);
mboom2->Play();
}
if (tempp.enemytype==7)
{
xg xgtemp(54,50,tempp.PPos.x,tempp.PPos.y,10,10,3);
vxg.push_back(xgtemp);
mboom3->Play();
}
if (tempp.enemytype==8)
{
xg xgtemp(65,75,tempp.PPos.x,tempp.PPos.y,12,6,2);
vxg.push_back(xgtemp);
mboom4->Play();
}
if (tempp.enemytype==9)
{
xg xgtemp(65,75,tempp.PPos.x,tempp.PPos.y,12,6,2);
vxg.push_back(xgtemp);
mboom1->Play();
}
if (tempp.enemytype==10)
{
xg xgtemp(65,75,tempp.PPos.x,tempp.PPos.y,12,6,2);
vxg.push_back(xgtemp);
mboom2->Play();
}
if (tempp.enemytype==2)
{
xg xgtemp(54,50,tempp.PPos.x,tempp.PPos.y,10,10,3);
vxg.push_back(xgtemp);
bullet bul(tempp.PPos.x-16,tempp.PPos.y+17,0,-3);
bullet bul1(tempp.PPos.x-16,tempp.PPos.y+17,-2,-2);
bullet bul2(tempp.PPos.x-16,tempp.PPos.y+17,-3,0);
bullet bul3(tempp.PPos.x-16,tempp.PPos.y+17,-2,2);
bullet bul4(tempp.PPos.x-16,tempp.PPos.y+17,0,3);
bullet bul5(tempp.PPos.x-16,tempp.PPos.y+17,2,2);
bullet bul6(tempp.PPos.x-16,tempp.PPos.y+17,3,0);
bullet bul7(tempp.PPos.x-16,tempp.PPos.y+17,2,-2);
pub.push_back(bul);
pub.push_back(bul1);
pub.push_back(bul2);
pub.push_back(bul3);
pub.push_back(bul4);
pub.push_back(bul5);
pub.push_back(bul6);
pub.push_back(bul7);
mboom3->Play();
}
}
if (player1.health<=0)
{
mboom1->Play();
xg xgtemp(54,50,player1.PPos.x,player1.PPos.y,10,10,3);
vxg.push_back(xgtemp);
player1.PPos.x =100;
player1.PPos.y=221;
player1.pmovidx=8;
player1.health=500;
player1.movestate =0;
player1.playerstate =0;
player1.bulltp=2;
player1.bullpw=3;
player1.boom=9;
rl.xgPos.x =66;
rl.xgPos .y =226;
player1.zd.clear ();
}
}
(*itpen)=tempp;
}
}
{
float a;
a=player1.health;
a/=500;
GetGraphics()->DrawBitmapZoom( 15,460,(int)(a*200),8,health , SCREENBUFFER );
GetGraphics()->DrawText(SCREENBUFFER,230,455,NULL,RGB2Hi(0,0,255),"BOOM=%d",player1.boom);
}
/*for (itbul=player1.zd.begin ();itbul!=player1.zd .end ();itbul++)
{
bullet temp;
temp=*itbul;
if (temp.type==0)
{
if (temp.power==0)
{
if (temp.status==BULLET_UNABLE){itbul=player1.zd.erase(itbul);}
}
if (temp.power==1)
{
if (temp.status==BULLET_UNABLE){itbul=player1.zd.erase(itbul);}
}
if (temp.power==2)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
if (temp.power==3)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
}
if (temp.type==1)
{
if (temp.power==0)
{
if (temp.status==BULLET_UNABLE){itbul=player1.zd.erase(itbul);}
}
if (temp.power==1)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
if (temp.power==2)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
if (temp.power==3)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul--;
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
}
if (temp.type==2)
{
if (temp.power==0)
{
if (temp.status==BULLET_UNABLE){itbul=player1.zd.erase(itbul);}
}
if (temp.power==1)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
if (temp.power==2)
{
int a=0;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
itbul++;
temp=*itbul;
if (temp.status!=BULLET_UNABLE){a=1;}
if (a==0){
itbul--;
itbul--;
itbul--;
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
itbul=player1.zd.erase(itbul);
}
}
if (temp.power==3)
{
vector<bullet>::iterator a,b,c;
a=itbul+1;
b=a+1;
c=b+1;
bullet temp1,temp2,temp3;
temp1=(*a);
temp2=(*b);
temp3=(*c);
if ((temp.status==BULLET_UNABLE)&&(temp1.status==BULLET_UNABLE)&&(temp2.status==BULLET_UNABLE)&&(temp3.status==BULLET_UNABLE))
{
itbul=player1.zd.erase(itbul,itbul+1);
itbul=player1.zd.erase(itbul,itbul+1);
itbul=player1.zd.erase(itbul,itbul+1);
itbul=player1.zd.erase(itbul,itbul+1);
}
}
}
(*itbul)=temp;
}*/
/* for (itpen=planeenemy.begin();itpen!=planeenemy.end();itpen++)
{
Cpenemy tempp;
tempp=*itpen;
int a=0;
for (itbul=tempp.zd.begin();itbul!=tempp.zd.end();itbul++)
{
bullet temp;
temp=*itbul;
if (temp.status!=BULLET_UNABLE)a=1;
(*itbul)=temp;
}
if (tempp.enemystate!=ENEMY_STATUS_DEAD) a=1;
if (a==0){
if ((itpen+1)!=planeenemy.end())
{
itpen=planeenemy.erase(itpen,itpen+1);
}
}
(*itpen)=tempp;
}
/* for(itxg=vxg.begin();itxg!=vxg.end();itxg++)
{
xg xgtemp;
xgtemp=*itxg;
if ((itxg+1)!=vxg.end ())
{
if (xgtemp.status!=XG_STATUS_NORMAL)
{
itxg=vxg.erase(itxg,itxg+1);
}
else
if (xgtemp.status!=XG_STATUS_NORMAL)
{
itxg=vxg.erase(itxg);
}
}
(*itxg)=xgtemp;
}*/
GetGraphics()->UpdateScreen( ); // 更新屏幕缓冲
GetGraphics()->Present( ); // DDraw更新屏幕
Sleep(30);
GetGraphics()->ClearScreenMMX(0); // 用黑色清屏
enemyidx++;
}
return 1;
}
int Game_Down(void)
{
GetGraphics()->RemoveBitmap(ppp);
GetGraphics()->RemoveBitmap(pxgw);
GetGraphics()->RemoveBitmap(pboss);
for (int i=0;i<7;i++)
{
GetGraphics()->RemoveBitmap(bg[i]);
}
for (int i=0;i<10;i++)
{
GetGraphics()->RemoveBitmap(bull[i]);
}
for (int i=0;i<12;i++)
{
GetGraphics()->RemoveBitmap(enemy[i]);
}
for (int i=0;i<11;i++)
{
GetGraphics()->RemoveBitmap(boom[i]);
}
for (int i=0;i<3;i++)
{
GetGraphics()->RemoveBitmap(pbouns[i]);
}
GetGraphics()->RemoveBitmap(health);
SAFE_DELETE(g_pDisplay)
SAFE_DELETE(g_pKeyboard );
return 1;
}
// 全局变量:
HINSTANCE hInst; // 当前实例
TCHAR szTitle[MAX_LOADSTRING]; // 标题栏文本
TCHAR szWindowClass[MAX_LOADSTRING]; // 主窗口类名
// 此代码模块中包含的函数的前向声明:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: 在此放置代码。
MSG msg;
HACCEL hAccelTable;
// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MYGAME, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MYGAME);
// 主消息循环:
Game_Main();
Game_Down();
return (int) msg.wParam;
}
//
// 函数: MyRegisterClass()
//
// 目的: 注册窗口类。
//
// 注释:
//
// 仅当希望在已添加到 Windows 95 的
// “RegisterClassEx”函数之前此代码与 Win32 系统兼容时,
// 才需要此函数及其用法。调用此函数
// 十分重要,这样应用程序就可以获得关联的
// “格式正确的”小图标。
//
ATOM MyRegisterClass(HINSTANCE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -