⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 object.cpp

📁 VC游戏编程基础
💻 CPP
📖 第 1 页 / 共 2 页
字号:


#include "global.h"
#include "object.h"

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CObject::CObject() {
	m_dwObjType	= OBJTYPE_NONE;
	m_dwObjStat = OBJSTAT_UNUSED;
	m_nStatCounter = 0;

	m_nWidth	= 0;
	m_nHeight	= 0;
	m_nLeft		= 0;
	m_nTop		= 0;
	
	m_dwFrameType	= 0;
	m_nTotalFrame	= 0;
	m_nCurrentFrame	= 0;
	m_dwPersistTime	= 0;
	m_dwLastTime	= 0;
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CObject::~CObject() {
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
RECT CObject::GetRect() {
	RECT	rc;
	SetRect( &rc, m_nLeft, m_nTop, m_nLeft+m_nWidth, m_nTop+m_nHeight );
	return rc;
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
void CObject::NextFrame( DWORD nowtime ) {
	if ( nowtime > m_dwPersistTime + m_dwLastTime ) {
		INCSCOPE( m_nCurrentFrame, 0, m_nTotalFrame );
		m_dwLastTime = nowtime;
	}
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CMobileObject::CMobileObject() {
	m_uiDirection = DIR_NONE;
	m_nMoveStep = 0;
	m_uiTeamType = TEAM_NEUTRAL;
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CMobileObject::~CMobileObject() {
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
RECT CMobileObject::GetNextRect() {
	RECT	rc = this->GetRect();
	POINT	pt = this->GetDirectionUnit();

	rc.left = m_nLeft + m_nMoveStep * pt.x;
	rc.top = m_nTop + m_nMoveStep * pt.y;
	rc.right = rc.left + m_nWidth;
	rc.bottom = rc.top + m_nHeight;

	return rc;
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
RECT CMobileObject::GetNextRectStep( int step ) {
	RECT	rc = this->GetRect();
	POINT	pt = this->GetDirectionUnit();

	rc.left = m_nLeft + step * pt.x;
	rc.top = m_nTop + step * pt.y;
	rc.right = rc.left + m_nWidth;
	rc.bottom = rc.top + m_nHeight;

	return rc;
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
POINT CMobileObject::GetDirectionUnit() {
	POINT	pt = {0,0};

	if ( m_uiDirection == DIR_RIGHT )			// right 
		pt.x = 1;
	else if ( m_uiDirection == DIR_LEFT )		// left
		pt.x = -1;
	else if ( m_uiDirection == DIR_UP ) 		// up
		pt.y = -1;
	else if ( m_uiDirection == DIR_DOWN ) 		// down
		pt.y = 1;
	
	return pt;
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CObjTank::CObjTank() {
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CObjTank::~CObjTank() {
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
void CObjTank::CreateTank( int left, int top, bool bHome ) {
	m_dwObjType	= OBJTYPE_TANK;
	m_dwObjStat = OBJSTAT_LIVE;
	m_dwEquip = 0;

	m_nWidth	= 32;
	m_nHeight	= 32;
	m_nLeft		= left;
	m_nTop		= top;
	
	m_dwFrameType	= LOC_OBJECT_TANK0;
	m_nTotalFrame	= 2;
	m_nCurrentFrame	= 0;
	m_dwPersistTime	= 0;

	m_uiDirection	= DIR_UP;
	m_nMoveStep		= DEFTANKSPEED;

	m_bMoving = false;
	m_bOnIce = false;
	m_nIceStep = 0;
	m_uiIceDir = DIR_NONE;

	m_nIndex = 0;
	m_bHome = bHome; 
	if ( m_bHome )
		m_uiTeamType = TEAM_HOME;
	else
		m_uiTeamType = TEAM_ENEMY;
	m_bBoom = false;
	m_bHaveBullet = false;
	m_prtBlood.CreateProperty( 30, 50, 0 );
	m_nAttack = 10;
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
void CObjTank::Hited( int attack ) {
	if ( !m_prtBlood.Minus( attack ) ) {
		m_nStatCounter = 2;
		m_dwObjStat = OBJSTAT_DIE;
		m_nTotalFrame	= 2;
		m_nCurrentFrame	= 0;
//		m_nPersistTime	= 100;
	}
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
void CObjTank::NextStat() {
	if ( m_dwObjStat == OBJSTAT_DIE ) {
		if ( --m_nStatCounter == 0 )
			m_dwObjStat = OBJSTAT_CADAVER;
	}
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
RECT CObjTank::GetNextRectOnIce() {
	RECT	rc = this->GetRect();
	POINT	pt = this->GetDirUnitOnIce();

	rc.left = m_nLeft + m_nIceStep * pt.x;
	rc.top = m_nTop + m_nIceStep * pt.y;
	rc.right = rc.left + m_nWidth;
	rc.bottom = rc.top + m_nHeight;

	return rc;
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
POINT CObjTank::GetDirUnitOnIce() {
	POINT	pt = {0,0};

	if ( m_uiIceDir == DIR_RIGHT )			// right 
		pt.x = 1;
	else if ( m_uiIceDir == DIR_LEFT )		// left
		pt.x = -1;
	else if ( m_uiIceDir == DIR_UP ) 		// up
		pt.y = -1;
	else if ( m_uiIceDir == DIR_DOWN ) 		// down
		pt.y = 1;
	
	return pt;
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CObjBullet::CObjBullet() {
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
CObjBullet::~CObjBullet() {
}


//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
void CObjBullet::CreateBullet( CObjTank *ptk )
{
	m_dwFrameType	= 0;
	m_nTotalFrame	= 1;
	m_nCurrentFrame	= 0;
	m_dwPersistTime	= 0;

	m_nMoveStep	= DEFBULLETSPEED;

	if ( ptk && ( ptk->GetStat() & OBJSTAT_LIVE )) {
		m_dwObjStat = OBJSTAT_LIVE;
		m_nLeft	= ptk->GetLeft()+8+(ptk->GetDirectionUnit().x)*8;
		m_nTop	= ptk->GetTop()+8+(ptk->GetDirectionUnit().y)*8;
		m_uiDirection	= ptk->m_uiDirection;
		m_bHome = ptk->IsHomeTeam();
		m_uiTeamType = ptk->m_uiTeamType;
		m_obkTank = ptk;
		ptk->SetBullet();
		m_nAttack	= ptk->m_nAttack;
	}
	else {
		m_dwObjType	= OBJTYPE_BULLET;
		m_nWidth	= DEFBULLETWIDTH;
		m_nHeight	= DEFBULLETHEIGHT;

		m_dwObjStat = OBJSTAT_CADAVER;
		m_nLeft	= 0;
		m_nTop	= 0;
		m_uiDirection = DIR_NONE;
	}
}

//-----------------------------------------------------------------------------
// Name: 
// Desc: 
//-----------------------------------------------------------------------------
void CObjBullet::NextStat() {
	if ( m_dwObjStat & OBJSTAT_LIVE ) {
		m_nStatCounter = 2;

⌨️ 快捷键说明

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