最新原創(chuàng)飛機大戰(zhàn)游戲設計與實現(xiàn)_第1頁
最新原創(chuàng)飛機大戰(zhàn)游戲設計與實現(xiàn)_第2頁
最新原創(chuàng)飛機大戰(zhàn)游戲設計與實現(xiàn)_第3頁
最新原創(chuàng)飛機大戰(zhàn)游戲設計與實現(xiàn)_第4頁
最新原創(chuàng)飛機大戰(zhàn)游戲設計與實現(xiàn)_第5頁
已閱讀5頁,還剩26頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、程序設計綜合實踐報告姓名學號班級項目名稱飛機大戰(zhàn)游戲設計與實現(xiàn)實習地點計算機實驗室實習時間2015-12-9 至 2015-12-19實習成績指導教師簽字信息科學與工程學院2015年12月20日3目錄1. 概述 11.1 關卡設置 11.2 敵機設置 11.3 戰(zhàn)機設置 21.4 游戲設置 22. 相關技術 22.1 Windows 定時器技術 . 22.2 雙緩沖技術 32.3 獲取矩形區(qū)域 33. 總體設計與詳細設計 33.1 系統(tǒng)模塊劃分 33.2 主要功能模塊 44. 編碼實現(xiàn) 44.1 初始準備 44.2 戰(zhàn)機對象 64.3 敵機對象 84.4 道具對象 94.5 主要內(nèi)容 104.

2、6 窗口顯示信息 195. 實訓中遇到的主要問題及解決方法 205.1 產(chǎn)生中斷及解決方案 205.2 圖片閃爍問題及解決方案 206. 實訓體會 22飛機大戰(zhàn)游戲設計與實現(xiàn)1. 概述項目:飛機大戰(zhàn)主要功能有以下幾點:1.1 關卡設置本次飛機大戰(zhàn)游戲中共設置了四個關卡, 第一關的難度設置較低, 僅有敵機 對其進行攻擊; 第二關在原有的基礎上增加一些補血的小道具, 當積分達到一定 的時候便會出現(xiàn)該道具, 并且敵機出現(xiàn)的頻率也比第一關高; 第三關在第二關的 基礎上新出現(xiàn)了小 boss ,并增加了其他的道具;第四關在第三關的基礎上再新 出現(xiàn)大 boss ,當積分達到要求以及大 boss 被消滅后通關

3、成功。1.2 敵機設置小敵機隨機出現(xiàn), 炮彈也隨機發(fā)射, 當小敵機與戰(zhàn)機相撞或被戰(zhàn)機的子彈擊 中時,小敵機消失。當達到一定積分時,小 boss 出現(xiàn)并隨機發(fā)射出與小敵機一 樣的炮彈,但是炮彈分三個方向發(fā)射出。當小 boss 被戰(zhàn)機的子彈擊中或與戰(zhàn)機 相撞時失去 5 滴血。當?shù)竭_四關并且積分足夠多時出現(xiàn)大 boss ,同小 boss 一 樣,當大 boss 與戰(zhàn)機相撞或被戰(zhàn)機子彈擊中時失去 1 滴血。除此之外, 小 boss 和大 boss 上方都有血條顯示, 當血條消失時意味著生命消失, 大 boss 和小 boss消失。小 boss 會在屏幕上隨機出現(xiàn)和走動出了屏幕后會在屏幕的任意地方再隨

4、機出現(xiàn),直至血量為 0 消失。大 boss 則在屏幕中隨機走動不出屏幕,直至血量 為 0 消失。1.3 戰(zhàn)機設置戰(zhàn)機初始有五條生命,每條命的血量為 50 ,所獲得的積分以及其生命值、 血條都在窗口的左上角顯示。 在第一、 二關時,按空格鍵戰(zhàn)機會出現(xiàn)兩個向上發(fā) 射的炮彈,到第三、四關的時候,按空格鍵戰(zhàn)機會發(fā)射三個不同方向的炮彈。戰(zhàn) 機吃到藥瓶道具時血量會增加 20 ,但不可以超過 50 ;吃到閃電道具時,便可放 大招,放大招的次數(shù)為 15 。當戰(zhàn)機被敵方的炮彈擊中或與敵方相撞時,血量減 少,減少為 0 時生命值減 1,直至生命值為 0 。1.4 游戲設置進入游戲時,會有背景音樂, 窗口左上角顯示

5、戰(zhàn)機所得積分及其生命值。 根 據(jù)積分情況進入不同的關卡。 游戲通關時屏幕清空, 并顯示通關成功, 按 Y 可重 新開始游戲。當戰(zhàn)機的血量以及生命值為 0 時,游戲失敗,屏幕清空并顯示游戲 結束,按 Y 即可重新開始游戲。2. 相關技術2.1 Windows 定時器技術Windows 定時器是一種輸入設備,它周期性地在每經(jīng)過一個指定的時間間隔后就通知應用程序一次。程序將時間間隔告訴 windows ,然后 windows 給 你的程序發(fā)送周期性發(fā)生的 WM_YIMER 消息以表示時間到了。本程序在OnCreate() 函數(shù)中使用了編號為 1 的定時器,控制了每 30 毫秒刷新一次。2.2 雙緩沖

6、技術在內(nèi)存中創(chuàng)建一個與屏幕繪圖區(qū)域一致的對象, 先將圖形繪制到內(nèi)存這個對 象上,再一次性將這個對象上的圖形拷貝到屏幕上, 這樣即可解決圖片閃爍問題。 本程序在繪制滾動背景以及飛機,敵機等中用到了該技術。2.3 獲取矩形區(qū)域用 CRect 定義一個對象,利用這個對象得到要用到的矩形區(qū)域,用IntersectRect 函數(shù)來判斷兩個源矩形是不是有重合的部分。3. 總體設計與詳細設計3.1 系統(tǒng)模塊劃分飛機大戰(zhàn)游戲主要模塊可以說是有幾個重要的類組成的。 首先是老師給出的 CGameObject 類,以及在其派生下的 Bomb,Ball,Enemy,MyPlane,Explosion,AddBlood

7、 等等此處不一一列舉。另外 還有 CObject 派生的 BackGround 類。如下圖:3CDhjedCassp-bli:pub icpublicpublicpublicCBdlld«£KSar% 的 KtCAddBemb dK- CGamfCslCBcmbChs% IGamsOb 十窩I?CBocfBrfClasiH' CGarrtDqjwtCBombZC133ECSanfCbjstCEnemyCjis* uGamfOb-fctpii?l cpublicpubl cCAddfioodCbssCGarrCtest匚Bo翡£1355T CGmrreZit

8、jM:CMyPlareCass峠;®FeC:bjPCLittleEoss 二I蒔fC Expl os ionl:Chsj出 CGmrregjeU3.2主要功能模塊主要功能是在飛機大戰(zhàn)View類中,On Timer函數(shù)中實現(xiàn),將各個類調(diào)用,隨機產(chǎn)生敵機,子彈的輸出,爆炸的實現(xiàn)等等。它的實現(xiàn)圖可以如下實現(xiàn):11本程序所包含的功能和類模塊:游戲子系統(tǒng)模塊名稱功能簡述應用程序對象游戲程序的加載、游戲對象的繪制、玩家的鍵盤事件獲取游戲對象各個游戲對象的抽象父類(CGameObject)戰(zhàn)機對象戰(zhàn)機類(MyPlane)敵機對象敵機類(Enemy, LittleBoss,Boss)導彈對象導彈類(

9、Bomb, Bomb2)炸彈對象炸彈類(Ball , BossBall)爆炸對象爆炸類(Explosion )道具對象道具類(AddBlood , AddBomb4.編碼實現(xiàn)4.1初始準備模塊名稱應用程序對象功能描述游戲程序的加載、游戲對象的繪制、玩家的鍵盤事件獲取數(shù)據(jù)結 構與算法CflyfightView:CflyfightView()/ TODO:在此處添加構造代碼flag=0;flag2=0;level=1; bossblood=100;CflyfightView:CflyfightView()BOOL CflyfightView:PreCreateWi ndow(CREATESTRUC

10、T & cs) / TODO:在此處通過修改/ CREATESTRUCT cs來修改窗口類或樣式 return CView:PreCreateWi ndow(cs);/ CflyfightView繪制void CflyfightView:O nDraw(CDC* pDC)CflyfightDoc* pDoc = GetDocume nt();ASSERT_VALID(pDoc);if (!pDoc)return;/ TODO:在此處為本機數(shù)據(jù)添加代碼/ CflyfightView打印BOOL CflyfightView:O nPreparePri ntin g(CPri ntlnfo*

11、 pI nfo)/默認準備return DoPreparePri nti ng(pl nfo);void CflyfightView:OnBeginPrinting(CDC* /*pDC*/, CPrintlnfo*/*pl nfo*/)/ TODO:添加額外的打印前進行的初始化過程void CflyfightView:O nEn dPri nti ng(CDC* /*pDC*/, CPrintlnfo* /*pI nfo*/)/ TODO:添加打印后進行的清理過程/ CflyfightView 診斷#ifdef _DEBUGvoid CflyfightView:AssertValid() c

12、on stCView:AssertValid();void CflyfightView:Dump(CDumpC on text & dc) constCView:Dump(dc);CflyfightDoc* CflyfightView:GetDocume nt() con st /非調(diào)試版本是內(nèi)聯(lián)的ASSERT(m_pDocume nt->lsKi ndOf(RUNTIME_CLASS(CflyfightDoc);return (CflyfightDoc*)m_pDocume nt;#en dif /_DEBUG/ CflyfightView 消息處理程序int Cflyfigh

13、tView:OnCreate(LPCREATESTRUCT lpCreateStruct)if (CView:O nCreate (l pCreateStruct) = -1)return -1;/ TODO:在此添加專用代碼和/或調(diào)用基類PlaySou nd(LPCTSTR)IDR_WAVE1, AfxGetI nsta nceHa ndle(),SND_RESOUR| SND_ASYNC|SND_LOOP);SetTimer(1,30, 0);CMyPla ne:LoadImage();CEn emy:LoadImage();CExplosi on:Loadlmage();CBomb:Lo

14、adlmage();CBall:LoadImage();CAddBlood:LoadImage();CAddBomb:LoadImage();CBomb2:Loadlmage();CLittleBoss:Loadlmage();CBoss:Loadlmage();CBossBall:Loadlmage();return 0;void CflyfightView:OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)/ TODO:在此添加消息處理程序代碼和/或調(diào)用默認值if(n Char=VK_DOWN|VK_UP)myPla ne.SetVerMotio

15、n(0);if(n Char=VK_RIGHT|VK_LEFT)myPla ne.SetHorMotio n(0);CView:O nKeyUp( nChar, nRepC nt, n Flags);補充說明4.2戰(zhàn)機對象模塊名稱戰(zhàn)機對象功能描述戰(zhàn)機移動、戰(zhàn)機導彈的發(fā)射數(shù)據(jù)結 構與算法short key=GetKeyState(VK_RIGHT);short key仁GetKeyState(VK_LEFT);short key2=GetKeyState(VK_UP);short key3=GetKeyState(VK_DOWN);if (key &0x80)!=0) myPla ne.

16、SetHorMotio n(1);else if (key1 &0x80)!=0)myPla ne.SetHorMotio n(-1);else if (key2&0x80)!=0) myPla ne.SetVerMotio n(-1);else if (key3&0 x80)!=0)myPla ne.SetVerMotio n(1);void CflyfightView:OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) / TODO:在此添加消息處理程序代碼和/或調(diào)用默認值if(n Char=VK_DOWN|VK_UP)my

17、Pla ne.SetVerMotio n(0);if(n Char=VK_RIGHT|VK_LEFT)myPla ne.SetHorMotio n(0);CView:O nKeyUp( nChar, nRepC nt, n Flags);void CflyfightView:O nKeyDow n( UINT n Char, UINT n RepC nt, UINT nFlags) / TODO:在此添加消息處理程序代碼和/或調(diào)用默認值if(n Char=VK_SPACE)if(myPla ne.Fired()if(flag=0&&(level=1|level=2)listBo

18、mb.AddTail( newCBomb(myPla ne.GetPoi nt().x+10,myPla ne.GetPoi nt().y+20,0,12); listBomb.AddTail( newCBomb(myPla ne.GetPoi nt().x+30,myPla ne.GetPoi nt().y+20,0,12);else if(flag=0&&(level=3|level=4)listBomb.AddTail( newCBomb(myPla ne.GetPoi nt().x+10,myPla ne.GetPoi nt().y+20,5,12); listBomb

19、.AddTail( newCBomb(myPla ne.GetPoi nt().x+30,myPla ne.GetPoi nt().y+20,0,12); listBomb.AddTail( newCBomb(myPla ne.GetPoi nt().x+30,myPla ne.GetPoi nt().y+20,-5,12);if(flag2!=0)listBomb2.AddTail( newCBomb2(myPla ne.GetPoi nt().x+10,myPla ne.GetPoi nt().y+20,10,10); listBomb2.AddTail( newCBomb2(myPla

20、ne.GetPoi nt().x+40,myPla ne.GetPoi nt().y+20,5,10); listBomb2.AddTail( newCBomb2(myPla ne.GetPoi nt().x+20,myPla ne.GetPoi nt().y+20,0,10); listBomb2.AddTail( newCBomb2(myPla ne.GetPoi nt().x+40,myPla ne.GetPoi nt().y+20,-5,10); listBomb2.AddTail( newCBomb2(myPla ne.GetPoi nt().x+40,myPla ne.GetPoi

21、 nt().y+20,-10,10); flag2-;if(flag2<1)flag=0;補充說明4.3敵機對象模塊名敵機對象稱功能描述敵機、大小boss隨機產(chǎn)生,隨機方向發(fā)射子彈,大boss隨機發(fā)射子彈,大小boss 的血條顯示數(shù)據(jù)結 構與算法/敵機的隨機產(chǎn)生if(level=1)if(ra nd()%30=10)listE nemy.AddTail( new CEn emy(); if(level=2|level=3)if(ra nd()%25=15)listE nemy.AddTail( new CEn emy();if(level=4)if(ra nd()%20=15)listE

22、 nemy.AddTail( new CEn emy();II大小Boss的隨機產(chǎn)生if(myPla ne.score%600=0&&level!=1 &&level!=2)listlboss.AddHead(new CLittleBoss();if(myPla ne.score=3630)listboss.AddHead( new CBoss();II敵機、Boss產(chǎn)生子彈posE nemy=listE nemy.GetHeadPositi on();while(posE nemy!=NULL)CEn emy *pE nemy=(CE nemy*)listE

23、nemy.GetNext(posE nemy);CPoi nt poi nt2=pE nemy->GetPoi nt();if(ran d()%60=1)listBall.AddTail( newCBall(poi nt2.x+10,poi nt2.y+10,0,-12);poslboss=listlboss.GetHeadPositi on();while(poslboss!=NULL)CLittleBoss *plboss=(CLittleBoss*)listlboss.GetNext(poslboss);CPoi nt poi nt3=plboss->GetPoi nt();

24、if(ran d()%50=1)listBall.AddTail( newCBall(poi nt3.x+10,poi nt3.y+10,-5,-12);listBall.AddTail( newCBall(poi nt3.x+10,poi nt3.y+10,0,-12);listBall.AddTail( newCBall(poi nt3.x+10,poi nt3.y+10,5,-12);posboss=listboss.GetHeadPositi on();while(posboss!=NULL)CBoss *pboss=(CBoss*)listboss.GetNext(posboss);

25、CPoi nt poi nt4=pboss->GetPoi nt();if(ran d()%40=1)listbossball.AddTail( newCBossBall(poi nt4.x+45,poi nt4.y+90,-5,-12);listbossball.AddTail( newCBossBall(poi nt4.x+45,poi nt4.y+90,0,-12);listbossball.AddTail( newCBossBall(poi nt4.x+45,poi nt4.y+10,5,-12);/大Boss血條顯示CBrush brush;brush.CreateSolidB

26、rush(RGB(255,0,0);pDC->SelectObject(brush);pDC->Recta ngle(m_ptPos.x,m_ptPos.y,m_ptPos.x+bblood*0.9,m_ptPos.y-5); /小Boss血條顯示CBrush brush;brush.CreateSolidBrush(RGB(255,0,0);pDC->SelectObject(brush);pDC->Recta ngle(m ptPos.x,m ptPos.y,m ptPos.x+lblood,m ptPos.y-5);補充說明4.4道具對象模塊名稱道具對象功能描述積

27、分達到一定的時候出現(xiàn)道具,戰(zhàn)機吃掉道具,道具消失,戰(zhàn)機補血或獲得技能數(shù)據(jù)結 構與算法if(myPla ne.score%510=0)listAddblood.AddHead(new CAddBlood();if(myPla ne.score%900=0&&level!=1) listaddbomb.AddHead( new CAddBomb();/*力廿血藥瓶 *POSITION posaddblood=listAddblood.GetHeadPositio n();POSITION pos4; for(posaddblood;(pos4=posaddblood)!=NULL;

28、)CAddBlood*paddblood=(CAddBlood*)listAddblood.GetNext(posaddblood);paddblood->Draw(&m _mDC,FALSE);CRect rect;intsectio n=rect .In tersectRect(paddblood->GetRect(),myPla ne.GetRect();if(sectio n!=0)if(myPla ne.blood<50)myPla ne.blood+=20;listAddblood.RemoveAt(pos4);delete paddblood;break

29、;/*技能道具 */POSITION posaddbomb=listaddbomb.GetHeadPositio n();POSITION pos5;for(posaddbomb;(pos5=posaddbomb)!=NULL;) CAddBomb*paddbomb=(CAddBomb*)listaddbomb.GetNext(posaddbomb); paddbomb->Draw(&m _mDC,FALSE);CRect rect;intsectio n=rect .In tersectRect(paddbomb->GetRect(),myPla ne.GetRect()

30、;if(sectio n!=0)flag=1;flag2=15;listaddbomb.RemoveAt(pos5);delete paddbomb;break;補充說明4.5主要內(nèi)容模塊名稱主要內(nèi)容功能描述戰(zhàn)機導彈擊中敵機和大小Boss,戰(zhàn)機與敵機和大小 Boss相撞,敵機和大小Boss發(fā)射的炮彈擊中戰(zhàn)機數(shù)據(jù)結 構與算法/戰(zhàn)機導彈擊中敵機POSITION pos1 = NULL;/ 刪除敵機POSITION pos2 = NULL,pos3=NULL; 刪除導彈for (posBomb = listBomb.GetHeadPosition(); (pos2=posBomb)!= NULL;)

31、CBomb *pBomb = (CBomb*)listBomb.GetNext(posBomb);for (posE nemy = listE nemy.GetHeadPositi on(); (pos仁posE nemy ) != NULL;)CRect in tersectRect;CEn emy *pE nemy = (CE nemy*)listE nemy.GetNext(posE nemy); int in tersectSectio n =in tersectRect.I ntersectRect(pE nemy->GetRect(), pBomb->GetRect()

32、;if (in tersectSect ion != 0)CRect eRect;eRect=pE nemy->GetRect();listExplosion.AddTail(new CExplosion(eRect.left, eRect.top);myPla ne.score+=30;if(myPla ne.score%510=0)listAddblood.AddHead( new CAddBlood();if(myPla ne.score%900=0&&level!=1) listaddbomb.AddHead( new CAddBomb();if(myPla ne

33、.score%600=0&&level!=1 &&level!=2) listlboss.AddHead(new CLittleBoss();if(myPla ne.score=3630)listboss.AddHead(new CBoss();listE nemy.RemoveAt(pos1); listBomb.RemoveAt(pos2);delete pEn emy;/ 刪除爆炸的對象delete pBomb;break;for(posBomb2=listBomb2.GetHeadPositio n();(pos3=posBomb2)!=NULL;) C

34、Bomb2 *pBomb2=(CBomb2*)listBomb2.GetNext(posBomb2);for (posE nemy = listE nemy.GetHeadPositi on(); (pos1=posE nemy ) != NULL;)CRect in tersectRect;CEn emy *pE nemy = (CE nemy*)listE nemy.GetNext(posE nemy); intsect= in tersectRect .In tersectRect(pE nemy->GetRect(),pBomb2->GetRect()if(sect!=0)

35、CRect eRect;eRect=pE nemy->GetRect();listExplosion.AddTail(new CExplosion(eRect.1 eft,eRect.top);myPla ne.score+=30;if(myPla ne.score%510=0)listAddblood.AddHead( new CAddBlood(); if(myPla ne.score%900=0&&level!=1)listaddbomb.AddHead( new CAddBomb();if(myPla ne.score%600=0&&level!=

36、1 &&level!=2) listlboss.AddHead(new CLittleBoss();if(myPla ne.score=3630)listboss.AddHead(new CBoss();listE nemy.RemoveAt(pos1);listBomb2.RemoveAt(pos3);delete pEn emy;delete pBomb2;break;/戰(zhàn)機導彈擊中小BossPOSITION posa = NULL;/ 刪除敵機POSITION pose = NULL,posc=NULL; 刪除導彈for (posBomb = listBomb.GetHe

37、adPositi on(); (pose=posBomb)!= NULL;) CBomb *pBomb = (CBomb*)listBomb.GetNext(posBomb);for (poslboss = listlboss.GetHeadPosition(); (posa=poslboss ) != NULL;)CRect in tersectRect;CLittleBoss *plboss =(CLittleBoss*)listlboss.GetNext(poslboss);int in tersectSectio n =in tersectRect.I ntersectRect(plb

38、oss->GetRect(), pBomb->GetRect();if (in tersectSect ion != 0)CRect eRect;eRect=plboss->GetRect();myPla ne.score+=30;if(myPla ne.score%510=0)listAddblood.AddHead( new CAddBlood();if(myPla ne.score%900=0&&level!=1)listaddbomb.AddHead( new CAddBomb();if(myPla ne.score%600=0&&le

39、vel!=1 &&level!=2) listlboss.AddHead(new CLittleBoss();if(myPla ne.score=3630) listboss.AddHead(new CBoss();if(plboss->lblood>0)plboss->lblood-=5;if(plboss->lblood<=0)listExplosio n. AddTail( new CExplosi on (eRect .left, eRect.top);plboss->lblood=0;listlboss.RemoveAt(posa)

40、; delete plboss;listBomb.RemoveAt(pose);/刪除爆炸的對象delete pBomb;break;for(posBomb2=listBomb2.GetHeadPositio n();(posc=posBomb2)!=NULL;) CBomb2 *pBomb2=(CBomb2*)listBomb2.GetNext(posBomb2);for (poslboss = listlboss.GetHeadPosition(); (posa=poslboss ) != NULL;)CRect in tersectRect;CLittleBoss *plboss =(C

41、LittleBoss*)listlboss.GetNext(poslboss);intsect=i ntersectRect.l ntersectRect(plboss->GetRect(),pBomb2->GetRect()if(sect!=0)CRect eRect;eRect=plboss->GetRect();myPla ne.score+=30;if(myPla ne.score%510=0) listAddblood.AddHead( new CAddBlood();if(myPla ne.score%900=0&&level!=1)15lista

42、ddbomb.AddHead( new CAddBomb();if(myPla ne.score%600=0&&level!=1 &&level!=2)listlboss.AddHead(new CLittleBoss();if(myPla ne.score=3630)listboss.AddHead(new CBoss();if(plboss->lblood>0)plboss->lblood-=5;if(plboss->lblood<=0)listExplosio n. AddTail( new CExplosi on (eRec

43、t .left, eRect.top);plboss->lblood=0;listlboss.RemoveAt(posa);delete plboss;listBomb2.RemoveAt(posc);delete pBomb2;break;戰(zhàn)機導彈擊中大Boss的原理基本與戰(zhàn)機擊中小Boss的相同,故此部分代碼不再給出/戰(zhàn)機撞到敵機POSITION posE nemy=listE nemy.GetHeadPositio n();POSITION pos=NULL;刪除戰(zhàn)機和敵機 for(posE nemy;(pos=posE nemy)!=NULL;) CEn emy *pE nemy

44、 = (CE nemy* )li stE nemy.GetNext(posE nemy);pEn emy->Draw(&m _mDC, FALSE);CRect rect;int sect ion = rect .In tersectRect(pE nemy->GetRect(),myPla ne.GetRect();if (sectio n != 0)CPoint point = myPlane.GetPoint();CRect eRect=pE nemy->GetRect();listExplosion.AddTail(new CExplosion(eRect.l

45、eft, eRect.top);explosio n.Draw(&m _mDC, FALSE);if(myPla ne.blood>0)19myPla ne.blood-=5;if(myPla ne.blood<=0&&m yPla ne.life>1)myPla ne.life-=1;myPla ne.blood=50+myPla ne.blood;else if(myPla ne.blood<=5&&m yPla ne.life=1)myPla ne.blood=0;myPla ne.life=0;CObject *d;d =

46、 listE nemy.GetAt(pos);listE nemy.RemoveAt(pos);delete d;break;II戰(zhàn)機撞到小BossPOSITION poslboss=listlboss.GetHeadPositio n(),posb=NULL;for(poslboss;(posb=poslboss)!=NULL;)CLittleBoss* plboss=(CLittleBoss*)listlboss.GetNext(poslboss);plboss->Draw(&m _mDC,FALSE);CRect rect;int sect ion = rect.ln te

47、rsectRect(plboss->GetRect(),myPla ne.GetRect();if(sectio n!=0)CRect eRect=myPla ne.GetRect();listExplosion.AddTail(new CExplosion(eRect.left, eRect.top);explosio n.Draw(&m _mDC, FALSE);if(myPla ne.blood>0)myPla ne.blood-=5;if(myPla ne.blood<=0&&m yPla ne.life>1)myPla ne.life-

48、=1;myPla ne.blood=50+myPla ne.blood;if(myPla ne.blood<=5&&m yPla ne.life=1)myPla ne.blood=0;myPla ne.life=O;if(plboss->lblood>0)plboss->lblood-=5;if(plboss->lblood<=0)plboss->lblood=0;listlboss.RemoveAt(posb);delete plboss;break;/戰(zhàn)機撞到大BossPOSITION posboss=listboss.GetHea

49、dPositio n( ),pos7=NULL;for(posboss;(pos7=posboss)!=NULL;)CBoss* pboss=(CBoss*)listboss.GetNext(posboss);pboss->Draw(&m _mDC,FALSE);CRect rect;int sect ion = rect.ln tersectRect(pboss->GetRect(), myPla ne.GetRect(); if(sectio n!=0)CRect eRect=myPla ne.GetRect();listExplosion.AddTail(new CE

50、xplosion(eRect.left, eRect.top);explosio n.Draw(&m _mDC, FALSE);if(myPla ne.blood>0)myPla ne.blood-=20;if(myPla ne.blood<=0&&m yPla ne.life>1)myPla ne.life-=1;myPla ne.blood=50+myPla ne.blood;if(myPla ne.blood<=5&&m yPla ne.life=1)myPla ne.blood=0;myPla ne.life=0;if(p

51、boss->bblood>0)pboss->bblood-=1;bossblood-=1;if(pboss->bblood<=0)listboss.RemoveAt(pos7);delete pboss;break;/敵機,小Boss發(fā)射炮彈擊中戰(zhàn)機POSITION posBall = listBall.GetHeadPositio n();POSITION pos6 = NULL;for (posBall; (pos6 = posBall) != NULL;)CBall *pBall = (CBall*)listBall.GetNext(posBall);pBa

52、ll->Draw(&m _mDC, FALSE);/戰(zhàn)機被敵機的炸彈打到時,戰(zhàn)機和炸彈都刪除CRect in tersectRect;int in tersectSectio n =in tersectRect.I ntersectRect(myPla ne.GetRect(), pBall->GetRect();CPoi nt pt=myPla ne.GetPoi nt();CPoi nt pt4=eBall.GetPoi nt();if (in tersectSect ion != 0)/爆炸效果CRect eRect;eRect=myPla ne.GetRect();

53、listExplosi on. AddTail( new CExplosi on( eRect .left, eRect.top); /從鏈表中刪除并釋放爆炸了的對象。if(myPla ne.blood>0)myPla ne.blood-=10;if(myPla ne.blood<=0&&m yPla ne.life>1)myPla ne.life-=1;myPla ne.blood=50+myPla ne.blood;else if(myPla ne.blood<=5&&m yPla ne.life=1)myPla ne.blood=0

54、;myPla ne.life=0;listBall.RemoveAt(pos6);delete pBall;break;/大Boss發(fā)射炮彈擊中戰(zhàn)機POSITION posbossball=listbossball.GetHeadPositio n();POSITION pos1 仁NULL;for (posbossball; (pos11 = posbossball) != NULL;)CBossBall *pbossball =(CBossBall*)listbossball.GetNext(posbossball);pbossball->Draw(&m _mDC, FALS

55、E);/戰(zhàn)機被敵機的炸彈打到時,戰(zhàn)機和炸彈都刪除CRect Rect;int Sectio n = Rect.ln tersectRect(myPla ne.GetRect(),pbossball->GetRect();if (Section != 0)/爆炸效果CRect eRect;eRect=myPla ne.GetRect();listExplosi on. AddTail( new CExplosi on( eRect .left, eRect.top); /從鏈表中刪除并釋放爆炸了的對象。if(myPla ne.blood>0)myPla ne.blood-=10;if(myPla ne.blood<=0&&m yPla ne.life>1)myPla ne.life-=1;myPla ne.blood=50+myPla ne.blood;else if(myPla ne.blood<=5&&m

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論