目录1. 概述 (1)2. 相关技术 (2)2.1碰撞检测 (2)2.2 CObList链表 (2)2.3 设置定时器 (2)2.4 背景滚动 (2)2.5内存释放技术 (2)3. 总体设计与详细设计 (2)3.1 系统模块划分 (2)3.2 主要功能模块 (3)4. 编码实现 (5)5. 实训中遇到的主要问题及解决方法 (37)6. 实训体会 (37)1. 概述这次实训,目的以VS 为环境,利用MFC,使用C++语言编写一个简单的飞机大战游戏。
实现的主要功能:1.有开始游戏界面,上下左右键控制飞机自由移动,空格键发射炮弹。
2.设有关卡,每打完一个boss就会过关,每过一关战机炮弹会升级,敌机随机发射子弹数量增加。
3.战机起始十条命,可以通过过关和吃到道具增加血量。
4.战机子弹打中敌机,敌机就会爆炸,boss血量随关卡升高而增多,打败敌机或者boss会有分数加成。
5.设有无敌模式和普通模式,无敌模式大招无限,生命无限,战机导弹直接升至最高等级。
2. 相关技术2.1碰撞检测用CRect类的GetRect()函数可以获得当前对象的矩形区域,IntersectRect()并用此函数判断二者是否碰撞。
2.2CObList链表这个程序使用CObList链表来存储各效果。
CobList类似于一个双向链表,POSITION 类型的变量为链表的键。
使用POSITION变量,既可以作为链表循环中的循环变量,也可以作为标记某个位置的标签。
我们可以通过获得某元素的POSITION来访问它。
本程序中主要用到的函数有:GetHeadPosition():获取链表首元素的POSITION;AddTail():将新的元素添加到链表最后;GetNext( POSITION& rPosition ):使rPosition指向下一个元素。
2.3 设置定时器SetTimer()函数来设置定时器。
2.4 背景滚动为了让游戏场景更加逼真,游戏节奏更加合理,可以通过让背景滚动来提高游戏的场景效应,实现这一技术时,可以将一张背景图片复制为2张,从上到下连续的拼接在一起,使其不会出现图片的卡顿和瞬移现象。
2.5内存释放技术这个程序中有大量的地方需要使用内存,如果不及时删除会出现闪图等情况,容易导致程序崩溃,要及时释放内存资源。
3. 总体设计与详细设计3.1 系统模块划分3.2 主要功能模块类关系图:4. 编码实现// PlaneGameView.cpp : CPlaneGameView 类的实现void CPlaneGameView::UpdateFrame(CDC* pMemDC){//绘制天空if(level==0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_BITMAP1);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}if(level>=1&&l==0&&boss==0){pMemDC->FillSolidRect(0, 0, GAME_WIDTH, GAME_HEIGHT, RGB(0, 0, 0));l++;z=1;}if(level==1&&l!=0&&boss!=0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_BITMAP1);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}if (level == 2 && l != 0 && boss != 0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_MAP2);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}if(level==3 && l != 0 && boss != 0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_MAP3);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}if(level==4 && l != 0 && boss != 0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_MAP4);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);//兼容BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}if(level==5 && l != 0 && boss != 0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_MAP5);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}if(level>5 && l != 0 && boss != 0){CPaintDC dc(this);CBitmap bmpBackground; //位图对象bmpBackground.LoadBitmap(IDB_MAP6);CDC dcMem; //定义一个工具箱(设备上下文)dcMem.CreateCompatibleDC(&dc);BITMAP bitmap;bmpBackground.GetBitmap(&bitmap); //建立绑定关系CBitmap *back = dcMem.SelectObject(&bmpBackground); //保存原有CDC对象,并选入新CDC对象入DCstatic int curr = 1;if (curr <= 1)curr = GAME_HEIGHT - 1;curr -= 1;pMemDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT - curr, &dcMem, 0, curr, SRCCOPY);pMemDC->BitBlt(0, GAME_HEIGHT - curr, GAME_WIDTH, curr, &dcMem, 0, 0, SRCCOPY);}pMemDC->SetBkMode(TRANSPARENT);pMemDC->SetTextAlign(TA_CENTER);pMemDC->SetTextColor(RGB(255, 255, 255));if(level==0){wchar_t S8[1000];wsprintf(S8, L"单击鼠标进入游戏");pMemDC->TextOutW(GAME_WIDTH / 2, GAME_HEIGHT / 2, CString(S8));}if(level>=1&&z!=0){wchar_t S9[1000];wsprintf(S9, L"点击进入下一关");pMemDC->TextOutW(GAME_WIDTH / 2, GAME_HEIGHT / 2, CString(S9)); }if(level>=1&&z==0){wchar_t S1[1000];wchar_t S2[1000];wsprintf(S1, L"得分:%d", number);wsprintf(S2, L"关卡:%d", level);pMemDC->TextOutW(35, 0, CString(S1));pMemDC->TextOutW(200, 0, CString(S2));wchar_t S3[1000];wsprintf(S3 , L"按下“F1”开启无敌模式");pMemDC->TextOutW(390, 0, CString(S3));wchar_t S4[1000];wsprintf(S4, L"按下“F2”关闭无敌模式");pMemDC->TextOutW(390, 20, CString(S4));wchar_t S5[1000];if(wu==0){ wsprintf(S5, L"大招数量:%d",dazhao );pMemDC->TextOutW(430, 40, CString(S5));}if(wu==1){wsprintf(S5, L"大招数量:无限");pMemDC->TextOutW(430, 40, CString(S5));}wchar_t S6[1000];wsprintf(S6, L"按下空格发射子弹");pMemDC->TextOutW(60, 50, CString(S6));wchar_t S7[1000];wsprintf(S7, L"按下“Z”大招");pMemDC->TextOutW(56, 70, CString(S7));//绘制我方战机if (m_pMe != NULL){m_pMe->Draw(m_pMemDC, FALSE);}else{ //Game OverCString str = _T("Game Over!");pMemDC->TextOut(GAME_WIDTH / 2, GAME_HEIGHT / 2, str);}//绘制血条if (m_pMe != NULL){CString z1;z1.Format(L"战机HP(%d)", shengming);pMemDC->TextOut(47, 30, z1);pMemDC->FillSolidRect(90, 33, shengming * 10, 10, RGB(255, 0, 0));if (bxt == 1){CString z2;z2.Format(L"Boss HP (%d)",boss);pMemDC->TextOut(35, 100, z2);pMemDC->FillSolidRect(80, 108, boss * 2, 10, RGB(0, 255, 0));}}//绘制导弹、爆炸、敌机、子弹、boss、boss子弹for (int i = 0;i <= 8;i++){POSITION pos1, pos2;for (pos1 = m_ObjList[i].GetHeadPosition(); (pos2 = pos1) != NULL; ){CGameObject* pObj = (CGameObject*)m_ObjList[i].GetNext(pos1);if (pObj && !pObj->Draw(pMemDC, FALSE)){m_ObjList[i].RemoveAt(pos2);delete pObj;}}}}//复制内存DC到设备DCm_pDC->BitBlt(0, 0, GAME_WIDTH, GAME_HEIGHT, m_pMemDC, 0, 0, SRCCOPY); }void CPlaneGameView::AI(){static int nCreator = rand() % 5+20 ;//随机产生敌机if (nCreator <= 0){nCreator = rand() % 5 +20;m_ObjList[enEnemy].AddTail(new CEnemy);}nCreator--;//随机产生大招if (count % 30 == 0){m_ObjList[endazhao].AddTail(new Cda);count++;}//随机产生生命if (count % 40 == 0){m_ObjList[enming].AddTail(new Cshengming);count++;}//产生bossif (level == 1&&bn==0&&count>=25&&count<=27) {m_ObjList[enboss].AddTail(new Cboss);bxt = 1;bn++;}if (level == 2&&bn==0&&count>=50&&count<=52) {m_ObjList[enboss].AddTail(new Cboss);bxt = 1;bn++;}if (level == 3&&bn==0&&count>=75&&count<=77) {m_ObjList[enboss].AddTail(new Cboss);bxt = 1;bn++;}if (level == 4&&bn==0&&count>=100&&count<=102) {m_ObjList[enboss].AddTail(new Cboss);bxt = 1;bn++;}if (level == 5&&bn==0&&count>=150&&count<=152) {m_ObjList[enboss].AddTail(new Cboss);bxt = 1;bn++;}if (level>5&&count%200==0&&bn==0){m_ObjList[enboss].AddTail(new Cboss);bxt = 1;bn++;}if (m_pMe == NULL)return;//检测四个方向键,移动战机for (int i = 0;i<4;i++){int nMeMotion = 0;m_pMe->SetVerMotion(0);m_pMe->SetHorMotion(0);nMeMotion = GetKey(VK_UP);if (nMeMotion == 1)m_pMe->SetVerMotion(1);nMeMotion = GetKey(VK_DOWN);if (nMeMotion == 1)m_pMe->SetVerMotion(-1);nMeMotion = GetKey(VK_RIGHT);if (nMeMotion == 1)m_pMe->SetHorMotion(1);nMeMotion = GetKey(VK_LEFT);if (nMeMotion == 1)m_pMe->SetHorMotion(-1);}//产生战机导弹if (GetKey(VK_SPACE) == 1)//按下了空格键{if (m_pMe != NULL && m_pMe->Fired()){CPoint pt = m_pMe->GetPoint();if (level == 1 && wu == 0){m_ObjList[enBomb].AddTail(new CBomb(pt.x + 20, pt.y + 10));}if (level == 2 && wu == 0){m_ObjList[enBomb].AddTail(new CBomb(pt.x + 10, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 30));}if (level == 3 && wu == 0){m_ObjList[enBomb].AddTail(new CBomb(pt.x + 10, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 20, pt.y + 30));}if (level >= 4 && wu == 0){m_ObjList[enBomb].AddTail(new CBomb(pt.x + 10, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 20, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x , pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 40, pt.y + 30));}if (wu == 1){m_ObjList[enBomb].AddTail(new CBomb(pt.x + 10, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 20, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x, pt.y + 30));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 40, pt.y + 30));}}}if (GetKey(VK_F1) == 1)//按下了F1{if (m_pMe != NULL && m_pMe->Fired()){wu = 1;}}if (GetKey(VK_F2) == 1 && wu == 1)//按下了F2{if (m_pMe != NULL && m_pMe->Fired()){wu = 0;}}//boss发射子弹static int num = 100;if (m_pMe != NULL && num <= 0){for (POSITION ePos = m_ObjList[enboss].GetHeadPosition(); ePos != NULL;) {Cboss* pEnemy = (Cboss*)m_ObjList[enboss].GetNext(ePos);CPoint ePt = pEnemy->GetPoint();CBossball * t;for (int i = -level + 1; i <= level - 1; i++){t = new CBossball(ePt.x + 20, ePt.y + 30);t->zx = int(4.0*sin((3.14* double(i)) / 9));t->zy = int(8.0*cos((3.14* double(i)) / 9));m_ObjList[enBossball].AddTail(t);}}num = 100;}num--;//敌机发射子弹if (m_pMe){CPoint PlanePt = m_pMe->GetPoint();for (POSITION ePos = m_ObjList[enEnemy].GetHeadPosition(); ePos != NULL;) {CEnemy* pEnemy = (CEnemy*)m_ObjList[enEnemy].GetNext(ePos);if (!pEnemy->Fired())continue;CPoint ePt = pEnemy->GetPoint();BOOL by = FALSE;//敌机在战机前面if (pEnemy->GetMontion() == 1 && ePt.y<PlanePt.y)by = TRUE;//敌机在战机后面if (pEnemy->GetMontion() == -1 && ePt.y>PlanePt.y)by = TRUE;if (by && ePt.x >= PlanePt.x && ePt.x < PlanePt.x + CMyPlane::PLANE_WIDTH){CBall * t;for (int i = -level + 1; i <= level - 1; i++){t = new CBall(ePt.x + 20, ePt.y + 30, -pEnemy->GetMontion());t->xx = int(8.0*sin((3.14* double(i)) / 9));t->xy = int(8.0*cos((3.14* double(i)) / 9));m_ObjList[enBall].AddTail(t);}}}}//boss子弹打到战机if (m_pMe != NULL){POSITION nPos3 = NULL, nPos4 = NULL;CRect mRect = m_pMe->GetRect();for (nPos3 = m_ObjList[enBossball].GetHeadPosition(); (nPos4 = nPos3) != NULL;){CBall* pBall = (CBall*)m_ObjList[enBossball].GetNext(nPos3);CRect bRect = pBall->GetRect();CRect tmpRect;if (tmpRect.IntersectRect(&bRect, mRect)){//添加爆炸效果if (wu == 0 ){shengming--;//生命减少}m_ObjList[enExplosion].AddTail(new CExplosion(mRect.left, mRect.top));//删除子弹m_ObjList[enBossball].RemoveAt(nPos4);delete pBall;if (shengming <= 0){//删除战机delete m_pMe;m_pMe = NULL;break;}}}}//敌机子弹打到战机if (m_pMe){POSITION nPos1 = NULL, nPos2 = NULL;CRect mnRect = m_pMe->GetRect();for (nPos1 = m_ObjList[enEnemy].GetHeadPosition(); (nPos2 = nPos1) != NULL;){CBall* pBall = (CBall*)m_ObjList[enEnemy].GetNext(nPos1);CRect bRect = pBall->GetRect();CRect tmpRect;if (tmpRect.IntersectRect(&bRect, mnRect)){//添加爆炸效果if (wu == 0 ){shengming--;//生命减少}m_ObjList[enExplosion].AddTail(new CExplosion(mnRect.left, mnRect.top));//删除子弹m_ObjList[enEnemy].RemoveAt(nPos2);delete pBall;if (shengming <= 0){//删除战机delete m_pMe;m_pMe = NULL;break;}}}}if (NULL != m_pMe) {//敌机撞战机POSITION bPos1 = NULL, bPos2 = NULL;CRect mRect = m_pMe->GetRect();for (bPos1 = m_ObjList[enBall].GetHeadPosition(); (bPos2 = bPos1) != NULL;) {CBall* pBall = (CBall*)m_ObjList[enBall].GetNext(bPos1);CRect bRect = pBall->GetRect();CRect tmpRect;if (tmpRect.IntersectRect(&bRect, mRect)){//添加爆炸效果if (wu == 0 ){shengming--;//生命减少}m_ObjList[enExplosion].AddTail(new CExplosion(mRect.left, mRect.top));//删除子弹m_ObjList[enBall].RemoveAt(bPos2);delete pBall;if (shengming <= 0){//删除战机delete m_pMe;m_pMe = NULL;break;}}}}//吃大招if (NULL != m_pMe) {POSITION bPos1 = NULL, bPos2 = NULL;CRect bRect = m_pMe->GetRect();for (bPos1 = m_ObjList[endazhao].GetHeadPosition(); (bPos2 = bPos1) != NULL;){CBall* pBall = (CBall*)m_ObjList[endazhao].GetNext(bPos1);CRect mRect = pBall->GetRect();CRect tmpRect;if (tmpRect.IntersectRect(&mRect, bRect)){dazhao++;//删除子弹m_ObjList[endazhao].RemoveAt(bPos2);delete pBall;}}}//吃生命if (NULL != m_pMe) {POSITION bPos1 = NULL, bPos2 = NULL;CRect mRect = m_pMe->GetRect();for (bPos1 = m_ObjList[enming].GetHeadPosition(); (bPos2 = bPos1) != NULL;) {CBall* pBall = (CBall*)m_ObjList[enming].GetNext(bPos1);CRect bRect = pBall->GetRect();CRect tmpRect;if (tmpRect.IntersectRect(&bRect, mRect)){shengming++;//删除子弹m_ObjList[enming].RemoveAt(bPos2);delete pBall;}}}//战机导弹炸掉敌机POSITION mPos1 = NULL, mPos2 = NULL;for (mPos1 = m_ObjList[enBomb].GetHeadPosition();(mPos2 = mPos1) != NULL;) {CBomb* pBomb = (CBomb*)m_ObjList[enBomb].GetNext(mPos1);CRect bRect = pBomb->GetRect();POSITION ePos1 = NULL, ePos2 = NULL;for (ePos1 = m_ObjList[enEnemy].GetHeadPosition();(ePos2 = ePos1) != NULL;){CEnemy* pEnemy = (CEnemy*)m_ObjList[enEnemy].GetNext(ePos1);CRect mRect = pEnemy->GetRect();CRect tmpRect;if (tmpRect.IntersectRect(&bRect, mRect)){count++;number += 5;//添加爆炸效果m_ObjList[enExplosion].AddTail(new CExplosion(mRect.left, mRect.top));//删除导弹if (da == 1){m_ObjList[enBomb].RemoveAt(mPos2);delete pBomb;}//删除敌机m_ObjList[enEnemy].RemoveAt(ePos2);delete pEnemy;break;}}}//战机导弹炸掉子弹POSITION mPos3 = NULL, mPos4 = NULL;for (mPos3 = m_ObjList[enBomb].GetHeadPosition(); (mPos4 = mPos3) != NULL;) {CBomb* pBomb = (CBomb*)m_ObjList[enBomb].GetNext(mPos3);CRect bRect = pBomb->GetRect();POSITION ePos3 = NULL, ePos4 = NULL;for (ePos3 = m_ObjList[enBall].GetHeadPosition(); (ePos4 = ePos3) != NULL;) {CBall* pBall = (CBall*)m_ObjList[enBall].GetNext(ePos3);CRect mRect = pBall->GetRect();CRect tmpRect;{//添加爆炸效果//删除导弹m_ObjList[enBomb].RemoveAt(mPos4);delete pBomb;//删除敌机m_ObjList[enBall].RemoveAt(ePos4);delete pBall;break;}}}//导弹炸掉bossPOSITION mPos5 = NULL, mPos6 = NULL;for (mPos5 = m_ObjList[enBomb].GetHeadPosition(); (mPos6 = mPos5) != NULL;) {CBomb* pBomb = (CBomb*)m_ObjList[enBomb].GetNext(mPos5);CRect bRect = pBomb->GetRect();POSITION ePos5 = NULL, ePos6 = NULL;for (ePos5 = m_ObjList[enboss].GetHeadPosition(); (ePos6 = ePos5) != NULL;) {Cboss* pBall = (Cboss*)m_ObjList[enboss].GetNext(ePos5);CRect mRect = pBall->GetRect();CRect tmpRect;{boss--;//添加爆炸效果m_ObjList[enExplosion].AddTail(new CExplosion(mRect.left, mRect.top));//删除导弹m_ObjList[enBomb].RemoveAt(mPos6);delete pBomb;if (boss <= 0){number = number + 100 * level;bxt = 0;//删除敌机m_ObjList[enboss].RemoveAt(ePos6);delete pBall;dazhao++;bn = 0;count = 0;shengming += 2;l=0;boss=0;break;}}}}}void CPlaneGameView::OnTimer(UINT_PTR nIDEvent){//刷新游戏帧画面: 在内存DC上绘图UpdateFrame(m_pMemDC);if ((beijing != GAME_HEIGHT))beijing += 2;elsebeijing = 0;AI();CView::OnTimer(nIDEvent);}void CPlaneGameView::On0(){// TODO: 在此添加命令处理程序代码}void CPlaneGameView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) {// TODO: 在此添加消息处理程序代码和/或调用默认值CView::OnKeyDown(nChar, nRepCnt, nFlags);if(nChar==90&&wu==1){CPoint pt = m_pMe->GetPoint();m_ObjList[enBomb].AddTail(new CBomb(pt.x - 50, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 20, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 70, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 130, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 550, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 520, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 160, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 490, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 460, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 190, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 430, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 400, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 220, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 370, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 340, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 250, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 310, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 280, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 60, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 90, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 120, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 150, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 570, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 180, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 540, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 510, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 210, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 480, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 450, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 240, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 390, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 270, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 360, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 330, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 300, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 50, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 20, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 70, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 100, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 130, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 550, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 520, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 160, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 490, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 460, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 190, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 430, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 400, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 220, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 370, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 340, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 250, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 310, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 280, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 60, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 120, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 150, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 570, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 180, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 540, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 510, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 210, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 480, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 450, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 240, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 420, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 390, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 270, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 360, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 330, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 300, pt.y + 60));} else if(nChar==90&&wu==0&&dazhao>=1){dazhao = dazhao - 1;CPoint pt = m_pMe->GetPoint();m_ObjList[enBomb].AddTail(new CBomb(pt.x - 50, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 20, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 70, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 100, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 130, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 550, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 520, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 160, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 490, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 460, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 190, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 430, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 400, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 220, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 370, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 340, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 250, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 310, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 280, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 60, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 90, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 120, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 150, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 570, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 180, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 540, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 510, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 210, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 480, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 450, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 240, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 420, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 390, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 270, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 360, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 330, pt.y + 80)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 300, pt.y + 80));m_ObjList[enBomb].AddTail(new CBomb(pt.x - 50, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 20, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 70, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 100, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 130, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 550, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 520, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 160, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 490, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 460, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 190, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 430, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 400, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 220, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 370, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 340, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 250, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 310, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x - 280, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 30, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 60, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 90, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 120, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 150, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 570, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 180, pt.y + 60)); m_ObjList[enBomb].AddTail(new CBomb(pt.x + 540, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 510, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 210, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 480, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 450, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 240, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 420, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 390, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 270, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 360, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 330, pt.y + 60));m_ObjList[enBomb].AddTail(new CBomb(pt.x + 300, pt.y + 60));}}void CPlaneGameView::OnLButtonDown(UINT nFlags, CPoint point){// TODO: 在此添加消息处理程序代码和/或调用默认值CView::OnLButtonDown(nFlags, point);if(level==0&&point.x>=0&&point.x<=512&&point.y>=0&&point.y<=768) level=1;if(level>=1&&boss<=0&&l==1&& point.x >= 0 && point.x <= 512 && point.y >= 0 && point.y <= 768){。