www.gusucode.com > VC++游戏雷霆战机源代码-源码程序 > VC++游戏雷霆战机源代码-源码程序\code\PlayerPlane.cpp
//Download by http://www.NewXing.com // PlayerPlane.cpp: implementation of the CPlayerPlane class. // ////////////////////////////////////////////////////////////////////// #include "PlayerPlane.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CPlayerPlane::CPlayerPlane(CDirectWnd *win, CObList *ObList, int lNum ):CPlane(win,ObList) { id = 0; width = 50; height = 60; posx = SrcWidth/2 - width/2; posy = SrcHeight; xspeed = 3; yspeed = 3; moveState = 0; bulletNum = 8; bulletType = 1; bulletLevel = 1; otime = timeGetTime(); stime = timeGetTime(); life = 1; bombNum = 3; lifeNum = lNum; super = TRUE; supertime = 3; canControl = FALSE; } CPlayerPlane::~CPlayerPlane() { } void CPlayerPlane::LoadPic() { PlanePic[0] = m_win->lpBKGObject[3]; PlanePic[1] = m_win->lpBKGObject[4]; PlanePic[2] = m_win->lpBKGObject[5]; } void CPlayerPlane::Action() { CheckKeyboard(); if( life < 0 ) { setExist(0); new CExplode(m_win, m_ObList, posx, posy, 0); m_win->m_snd->PlaySound(1,0); lifeNum-- ; if(lifeNum > 0) { new CPlayerPlane(m_win,m_ObList,lifeNum); } } // 显示飞机数量 RECT rSrc,rDest; m_win->GetRect(&rDest,20,SrcHeight - 40,25,30); m_win->BltObject(PlanePic[0],NULL,&rDest); m_win->ShowText(50,SrcHeight - 30,"x"); m_win->ShowText(65,SrcHeight - 30,lifeNum); // 显示炸弹数量 m_win->GetRect(&rSrc,0,40,40,40); m_win->GetRect(&rDest,80,SrcHeight - 35,20,20); m_win->BltObject(m_win->lpBKGObject[9],&rSrc,&rDest); m_win->ShowText(110,SrcHeight - 30,"x"); m_win->ShowText(125,SrcHeight - 30,bombNum); } void CPlayerPlane::Fire() { if(CPlayerBullet::num <= bulletNum * bulletLevel) { if (timeGetTime()-otime > 50) { otime = timeGetTime(); switch(bulletLevel) { case 1: { if( 1 == bulletType ) { new CPlayerBullet( m_win, m_ObList, posx+17, posy-5, 0, 5, 2); } else if( 2 == bulletType ) { new CPlayerBullet( m_win, m_ObList, posx+18, posy-5, 0, 5, 3); } } break; case 2: { if( 1 == bulletType ) { new CPlayerBullet( m_win, m_ObList, posx+10, posy-5, 0, 5, 2); new CPlayerBullet( m_win, m_ObList, posx+24, posy-5, 0, 5, 2); } else if( 2 == bulletType ) { new CPlayerBullet( m_win, m_ObList, posx+18, posy-5, 0, 5, 3); } } break; case 3: { if( 1 == bulletType ) { for(int i = 0 ; i < 3; i++) { new CPlayerBullet( m_win, m_ObList, posx+10, posy-5, i-1, 5, 2); } } else if( 2 == bulletType ) { new CPlayerBullet( m_win, m_ObList, posx+14, posy-5, 0, 5, 3); new CPlayerBullet( m_win, m_ObList, posx+22, posy-5, 0, 5, 3); } } break; case 4: { if( 1 == bulletType ) { for(int i = 0 ; i < 5; i++) { new CPlayerBullet( m_win, m_ObList, posx+17, posy-5, i-2, 5, 2); } } else if( 2 == bulletType ) { for(int i = 0; i < 3; i++) { new CPlayerBullet( m_win, m_ObList, posx+11+7*i, posy-5, 0, 5, 3); } } } break; case 5: { if( 1 == bulletType ) { for(int i = 0 ; i < 7; i++) { new CPlayerBullet( m_win, m_ObList, posx+17, posy-5, i-3, 5, 2); } } else if( 2 == bulletType ) { for(int i = 0; i < 4; i++) { new CPlayerBullet( m_win, m_ObList, posx+8+7*i, posy-5, 0, 5, 3); } } } break; } // m_win->m_snd->PlaySound(6,0); } } } void CPlayerPlane::CheckKeyboard() { if (super==TRUE) if (timeGetTime() > stime + supertime*1000) { stime = timeGetTime(); super=FALSE; } RECT rtDest = {posx,posy,posx+50,posy+60}; if ( canControl == TRUE ) { moveState = 0; if(KEYDOWN(VK_LEFT)) { posx -= xspeed; if( posx < 0 ) posx = 0; moveState = 1; } if(KEYDOWN(VK_RIGHT)) { posx += xspeed; if( posx > SrcWidth - width ) posx = SrcWidth - width; moveState = 2; } if(KEYDOWN(VK_UP)) { posy -= yspeed; if( posy < 0 ) posy = 0; } if(KEYDOWN(VK_DOWN)) { posy += yspeed; if(posy > SrcHeight - height) posy = SrcHeight - height; } if(KEYDOWN(VK_CONTROL)) { Fire(); } if(KEYDOWN(VK_MENU)) { if ( 0 == CBomb::num && bombNum > 0 ) { new CBomb(m_win,m_ObList); bombNum --; } } } else { if (posy > SrcHeight - 100 ) //飞机刚出现时是无法控制的 { posy -= yspeed; } else canControl=TRUE; } if (super==TRUE) //无敌时的闪烁效果 { static int ot=0;//延时 if (timeGetTime()-ot > 20) ot = timeGetTime(); else return; } // 显示飞机 m_win->BltObject(PlanePic[moveState],NULL,&rtDest); } void CPlayerPlane::getBonus(int type) { //type 0:子弹一 1:子弹二 2: 炸弹 3: 无敌 4: 子弹全满 switch(type) { case 0: if( 1 == bulletType ) { if(bulletLevel < 5) bulletLevel++; } else if( 2 == bulletType ) { bulletType = 1; } break; case 1: if( 1 == bulletType ) { bulletType = 2; } else if( 2 == bulletType ) { if(bulletLevel < 5) bulletLevel++; } break; case 2: bombNum++; break; case 3: super = TRUE; supertime = 20; stime = timeGetTime(); break; case 4: bulletLevel = 5; break; } }