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

📄 gameobject.cpp

📁 一个类似坦克大战的小小游戏
💻 CPP
字号:
// Object.cpp: implementation of the CObject class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
//#include "MapEdit.h"
#include "GameObject.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

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

CGameObject::CGameObject()
{
	m_objType = OT_UnDefined;
	m_nHeight = 0;
	m_nWidth = 0;
	m_nX = 0;
	m_nY = 0;
	m_nTextureIndex = -1;
	m_nIndex = -1;
//	m_pTexture = NULL;	// DELETE by vigame, 2007-7-8
	m_nHp = 10000;	// To set to a biggish value, so we "can't" destory it.
}

CGameObject::~CGameObject()
{
	//	SAFE_DELETE(m_pTexture);	// DELETED by vigame, 2007-7-8, we release texture at ~CObjectTexture()	
	m_pTexture = NULL;
}

// Overload the operator //////////////////////////////////////////////

bool CGameObject::operator <(const CGameObject &otherObject) const
{
	return ((m_nY + m_nHeight) < (otherObject.m_nY + otherObject.m_nHeight));
}

bool CGameObject::operator >(const CGameObject &otherObject) const
{
	return ((m_nY + m_nHeight) > (otherObject.m_nY +otherObject.m_nHeight));
}

// Get Size ///////////////////////////////////////////////////////////

int CGameObject::GetHeight()
{
	return m_nHeight;
}

int CGameObject::GetWidth()
{
	return m_nWidth;
}

// Draw /////////////////////////////////////////////////////////////////////

void CGameObject::Draw(LPDIRECT3DTEXTURE9 &pTexture, LPDIRECT3DDEVICE9 &pDevice, int x, int y)
{
	Draw(m_pTexture, pDevice, x, y, m_nWidth, m_nHeight, D3DCOLOR_ARGB(255, 255, 255, 255));
}

void CGameObject::Draw(LPDIRECT3DDEVICE9 &pDevice, int x, int y)
{
	Draw(m_pTexture, pDevice, x, y, m_nWidth, m_nHeight, D3DCOLOR_ARGB(255, 255, 255, 255));
}

void CGameObject::Draw(LPDIRECT3DTEXTURE9 &pTexture, LPDIRECT3DDEVICE9 &pDevice,	
						int x, int y, int width, int height, DWORD diffuse)
{
	CUSTOMVERTEX vertex[4];
	memset(vertex, 0, sizeof(vertex));

	// Set picture position
	vertex[0].x = (float)x;
	vertex[0].y = (float)y;
	vertex[0].z = 0.5f;
	vertex[1].x = (float)(x + width);
	vertex[1].y = (float)y;
	vertex[1].z = 0.5f;
	vertex[2].x = (float)(x + width);
	vertex[2].y = (float)(y + height);
	vertex[2].z = 0.5f;
	vertex[3].x = (float)x;
	vertex[3].y = (float)(y + height);
	vertex[3].z = 0.5f;

	// Set rhw
	vertex[0].rhw = 0.5f;
	vertex[1].rhw = 0.5f;
	vertex[2].rhw = 0.5f;
	vertex[3].rhw = 0.5f;

	// Set diffuse;
	vertex[0].diffuse = diffuse;
	vertex[1].diffuse = diffuse;
	vertex[2].diffuse = diffuse;
	vertex[3].diffuse = diffuse;

	// Set UV position
	vertex[1].tu = 1.0f;
	vertex[2].tu = 1.0f;
	vertex[2].tv = 1.0f;
	vertex[3].tv = 1.0f;

	// Draw object
	pDevice->SetTexture(0 , pTexture);
	pDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
	pDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, (LPVOID)vertex , sizeof(CUSTOMVERTEX));
}

// Create texture //////////////////////////////////////////////////////
/* DELETED by vigame, 2007-7-8
BOOL CGameObject::CreateTexture(LPDIRECT3DDEVICE9 pDevice, LPCTSTR inFileName, DWORD inColorKey)
{
	if (OT_UnDefined == m_objType)
	{
		return FALSE;
	}

	// To figure out the frames we should create
	int nFrameCount = 0;
	switch (m_objType)
	{
	case OT_Boat_Player:
		{
			nFrameCount = 12;
			break;
		}
	default:
		{
			nFrameCount = 1;
			break;
		}
	}

	m_pTexture = new CObjectTexture [nFrameCount];

	// Create texture now
	int i;
	for (i = 0; i < nFrameCount; i++)
	{
		m_pTexture[i].Create(pDevice, inFileName, inColorKey);
	}

	// Get the size of texture
	m_nWidth = m_pTexture[0].GetWidth();
	m_nHeight = m_pTexture[0].GetHeight();

	return TRUE;
}

*/

⌨️ 快捷键说明

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