附录4:防空战游戏程序 365 BITMAP BM m bmp Tank. Get Bitmap(&BM) Width= bm. bmwidth m nHeight BM. bmHeight //显示高炮 void CTank: ShowTank(CDC *pDC, CDC *pMemDC, CRect Client) pMemDC->SelectObject(&m bmp Tank) pDC->BitBlt(m pointTank x, m pointTank y, m nWidth, m nHeight, pMemDC, 0, 0, SRCAND) /改变位置 void CTank:: ChangePos (int tag) if(tag ==0&&m pointTank x>0) m pointTank. X - 20 else if(tag = 1 & m pointTank. x+m nWidth 798) m pointTank. x +=20 //定义炮弹类 class STone: public Cob ject CPoint m pointstone;//炮弹位置 CBitmap m bmpstone /炮弹图象 int m nWidth: /炮弹图象宽 int m nHeight //炮弹图象高 BOOM sHot;//是否已发射 BOOLHaveStone o return ! m sHot: 1 void Shot(int x) voidShowStone(CDC *pDC, CDC =pMemDC, CRect Client) CRect GetStoneo freturn CRect(m pointStone. x, m pointStone y m pointstone xtm nWidth, m pointStone. y+m nHeight); void ChangePos o voidResetPosoim sHot FALSE: H附录 4:防空战游戏程序 - 365 - BITMAP BM; m_bmpTank.GetBitmap(&BM); m_nWidth= BM.bmWidth; m_nHeight = BM.bmHeight; } // 显示高炮 void CTank::ShowTank(CDC *pDC, CDC *pMemDC, CRect Client) { pMemDC->SelectObject(&m_bmpTank); pDC->BitBlt(m_pointTank.x, m_pointTank.y, m_nWidth, m_nHeight, pMemDC,0,0,SRCAND); } // 改变位置 void CTank::ChangePos(int tag) { if(tag == 0 && m_pointTank.x > 0) m_pointTank.x -= 20; else if(tag == 1 && m_pointTank.x+m_nWidth < 798) m_pointTank.x += 20; } // 定义炮弹类 class CStone: public CObject { CPoint m_pointStone; // 炮弹位置 CBitmap m_bmpStone; // 炮弹图象 int m_nWidth; // 炮弹图象宽 int m_nHeight; // 炮弹图象高 BOOLm_bShot; // 是否已发射 public: CStone(); BOOLHaveStone(){return !m_bShot;} voidShot(int x); voidShowStone(CDC *pDC, CDC *pMemDC, CRect Client); CRect GetStone(){return CRect(m_pointStone.x, m_pointStone.y, m_pointStone.x+m_nWidth, m_pointStone.y+m_nHeight);} voidChangePos(); voidResetPos(){m_bShot = FALSE;}