bonus.cpp

来自「一个打飞机的小游戏的源代码」· C++ 代码 · 共 80 行

CPP
80
字号
// Bonus.cpp: implementation of the CBonus class.
//
//////////////////////////////////////////////////////////////////////

#include "Bonus.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBonus::CBonus(CDirectWnd *win,
			   CObList *ObList,
			   int px,
			   int py,
			   int xspd,
			   int yspd,
			   int btype):CBaseObj(win,ObList)
{
	id = 4;
	posx = px;
	posy = py;
	xspeed = xspd;
	yspeed = yspd;
	bonusType = btype;
	width = 40;
	height = 40;
}

CBonus::~CBonus()
{

}

void CBonus::LoadPic()
{
	BonusPic = m_win->lpBKGObject[9];
}

void CBonus::Action()
{
	RECT rtSrc,rtDest;
	//type 0:子弹一 1:子弹二 2: 炸弹 3: 无敌 4: 子弹全满
	switch(bonusType)
	{
	case 0:
		m_win->GetRect(&rtSrc,0,0,40,40);
		m_win->GetRect(&rtDest,posx,posy,40,40);
		m_win->BltObject(BonusPic,&rtSrc,&rtDest);
		break;
	case 1:
		m_win->GetRect(&rtSrc,40,0,40,40);
		m_win->GetRect(&rtDest,posx,posy,40,40);
		m_win->BltObject(BonusPic,&rtSrc,&rtDest);
		break;
	case 2:
		m_win->GetRect(&rtSrc,0,40,40,40);
		m_win->GetRect(&rtDest,posx,posy,40,40);
		m_win->BltObject(BonusPic,&rtSrc,&rtDest);
		break;
	case 3:
		m_win->GetRect(&rtSrc,40,40,40,40);
		m_win->GetRect(&rtDest,posx,posy,40,40);
		m_win->BltObject(BonusPic,&rtSrc,&rtDest);
		break;
	case 4:
		m_win->GetRect(&rtSrc,0,80,40,40);
		m_win->GetRect(&rtDest,posx,posy,40,40);
		m_win->BltObject(BonusPic,&rtSrc,&rtDest);
		break;
	}

	posy += yspeed;

	if( posx < 0 || posx > SrcWidth - width ||
		posy < 0 || posy > SrcHeight - height)
	{
		setExist(0);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?