bullet.cpp

来自「一个坦克大战的源码」· C++ 代码 · 共 60 行

CPP
60
字号
// Bullet.cpp: implementation of the CBullet class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Bullet.h"
#include "MainGame.h"

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

CBullet::CBullet(int px,int py,int type,int power,int bulletSpeed,int direction):CWeapon(this)
{
	positionX=px;
	positionY=py;
	this->type=type;
	CWeapon::type=type;
	this->power=power;
	speed=bulletSpeed;
	this->direction=direction;
	width=6;
	height=6;
////////////////////////////
	bulletSpeed=5;
	power=10;

	switch(direction)//设置子弹的具体位置.32*32 子弹:6*6
	{
	case 0:	positionX+=13; positionY-=6;  break;
	case 1: positionX+=32; positionY+=13; break;
	case 2:	positionX+=13; positionY+=32; break;
	case 3:	positionX-=6; positionY+=13; break;
	}	

	strcpy(name,"bullet");
}

CBullet::~CBullet()
{

}


void CBullet::displayObject()
{
	CMainGame *pWnd=(CMainGame*)AfxGetMainWnd();
	CRect rt1(positionX,positionY,positionX+width,positionY+height);
	CRect rt2(8*direction,0,8*(direction+1),8);
	pWnd->BltBitMap(pWnd->lpBackBuffer,rt1,pWnd->lpBKGObject[4],rt2);
}

bool CBullet::ActiveObject()
{
	displayObject();
	return CWeapon::ActiveObject();
}


⌨️ 快捷键说明

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