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

📄 gameresource.cpp

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

#include "GameResource.h"

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

// Scene pictures path defined ///////////////////////////////////////

const char * SEA_PATH_DEBUG = "..\\pics\\sea\\sea%d.bmp";
const char * SEA_PATH = ".\\pics\\sea\\sea%d.bmp";

const char * ISLAND_PATH_DEBUG = "..\\pics\\island\\island%d.bmp";
const char * ISLAND_PATH = ".\\pics\\island\\island%d.bmp";

const char * WALL_PATH_DEBUG = "..\\pics\\wall\\wall%d.bmp";
const char * WALL_PATH = ".\\pics\\wall\\wall%d.bmp";

const char * REEF_PATH_DEBUG = "..\\pics\\reef\\reef%d.bmp";
const char * REEF_PATH = ".\\pics\\reef\\reef%d.bmp";

const char * BARBETTE_PATH_DEBUG = "..\\pics\\barbette\\barbette%d.bmp";
const char * BARBETTE_PATH = ".\\pics\\barbette\\barbette%d.bmp";

const char * FENSE_PATH_DEBUG = "..\\pics\\fense\\fense%d.bmp";
const char * FENSE_PATH = ".\\pics\\fense\\fense%d.bmp";

const char * SEAWEED_PATH_DEBUG = "..\\pics\\seaweed\\seaweed0.bmp";
const char * SEAWEED_PATH = ".\\pics\\seaweed\\seaweed0.bmp";

const char * WARSHIP_PATH_DEBUG = "..\\pics\\warship\\warship%d.bmp";
const char * WARSHIP_PATH = ".\\pics\\warship\\warship%d.bmp";

const char * BULLET_PATH_DEBUG = "..\\pics\\bullet\\bullet%d.bmp";
const char * BULLET_PATH = ".\\pics\\bullet\\bullet%d.bmp";

const char * FIREWORKS_PATH_DEBUG = "..\\pics\\fireworks\\fireworks%d.bmp";
const char * FIREWORKS_PATH = ".\\pics\\fireworks\\fireworks%d.bmp";

const char * BONUS_PATH_DEBUG = "..\\pics\\bonus\\bonus%d.dds";
const char * BONUS_PATH = ".\\pics\\bonus\\bonus%d.dds";

const char * STATE_PATH_DEBUG = "..\\pics\\state%d.jpg";
const char * STATE_PATH = ".\\pics\\state%d.jpg";

// Boat pictures defined

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

CGameResource::CGameResource()
{

}

CGameResource::~CGameResource()
{
	ReleaseAll();
}

// Load all ///////////////////////////////////////////////////////////

BOOL CGameResource::LoadAll(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	BOOL bRtn = TRUE;
	bRtn &= LoadSea(pDevice, inColorKey);
	bRtn &= LoadIsland(pDevice, inColorKey);
	bRtn &= LoadWall(pDevice, inColorKey);
	bRtn &= LoadReef(pDevice, inColorKey);
	bRtn &= LoadBarbette(pDevice, inColorKey);
	bRtn &= LoadFense(pDevice, inColorKey);
	bRtn &= LoadSeaweed(pDevice, inColorKey);
	bRtn &= LoadWarship(pDevice, inColorKey);
	bRtn &= LoadBullet(pDevice, inColorKey);
	bRtn &= LoadFireworks(pDevice, inColorKey);
	bRtn &= LoadBonus(pDevice, inColorKey);
	bRtn &= LoadState(pDevice, inColorKey);
	return bRtn;
}

// Load Sea /////////////////////////////////////////////////////////////

BOOL CGameResource::LoadSea(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < SEA_COUNT; i++)
	{
		wsprintf(strPath, SEA_PATH_DEBUG, i);
		if (!m_textureSea[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, SEA_PATH, i);
			if (!m_textureSea[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find sea%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load island /////////////////////////////////////////////////////////////

BOOL CGameResource::LoadIsland(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < ISLAND_COUNT; i++)
	{
		wsprintf(strPath, ISLAND_PATH_DEBUG, i);
		if (!m_textureIsland[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, ISLAND_PATH, i);
			if (!m_textureIsland[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find island%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load wall ////////////////////////////////////////////////////////////////

BOOL CGameResource::LoadWall(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < WALL_COUNT; i++)
	{
		wsprintf(strPath, WALL_PATH_DEBUG, i);
		if (!m_textureWall[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, WALL_PATH, i);
			if (!m_textureWall[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find wall%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load reef /////////////////////////////////////////////////////////////////

BOOL CGameResource::LoadReef(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < REEF_COUNT; i++)
	{
		wsprintf(strPath, REEF_PATH_DEBUG, i);
		if (!m_textureReef[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, REEF_PATH, i);
			if (!m_textureReef[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find reef%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load barbette ////////////////////////////////////////////////////////////

BOOL CGameResource::LoadBarbette(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < BARBETTE_COUNT; i++)
	{
		wsprintf(strPath, BARBETTE_PATH_DEBUG, i);
		if (!m_textureBarbette[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, BARBETTE_PATH, i);
			if (!m_textureBarbette[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find barbette%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load fense ///////////////////////////////////////////////////////////////

BOOL CGameResource::LoadFense(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < FENSE_COUNT; i++)
	{
		wsprintf(strPath, FENSE_PATH_DEBUG, i);
		if (!m_textureFense[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, FENSE_PATH, i);
			if (!m_textureFense[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find fense%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load Seaweed //////////////////////////////////////////////////////////////

BOOL CGameResource::LoadSeaweed(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	if (!m_textureSeaweed.Create(pDevice, SEAWEED_PATH_DEBUG, inColorKey))
	{
		if (!m_textureSeaweed.Create(pDevice, SEAWEED_PATH, inColorKey))
		{
			MessageBox(NULL, "Could not find seaweed0.bmp", "WARNING!", MB_ICONWARNING);
			return FALSE;
		}
	}
	return TRUE;
}

// Load Warship //////////////////////////////////////////////////////////////

BOOL CGameResource::LoadWarship(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < 20; i++)
	{
		wsprintf(strPath, WARSHIP_PATH_DEBUG, i);
		if (!m_textureWarship[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, WARSHIP_PATH, i);
			if (!m_textureWarship[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find warship%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}

	// The color key is purple
	for (i = 20; i < 28; i++)
	{
		wsprintf(strPath, WARSHIP_PATH_DEBUG, i);
		if (!m_textureWarship[i].Create(pDevice, strPath, D3DCOLOR_ARGB(255, 255, 0, 255)))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, WARSHIP_PATH, i);
			if (!m_textureWarship[i].Create(pDevice, strPath, D3DCOLOR_ARGB(255, 255, 0, 255)))
			{
				wsprintf(strPath, "Could not find warship%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}

	// The color key is white
	for (i = 28; i < 32; i++)
	{
		wsprintf(strPath, WARSHIP_PATH_DEBUG, i);
		if (!m_textureWarship[i].Create(pDevice, strPath, D3DCOLOR_ARGB(255, 255, 255, 255)))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, WARSHIP_PATH, i);
			if (!m_textureWarship[i].Create(pDevice, strPath, D3DCOLOR_ARGB(255, 255, 255, 255)))
			{
				wsprintf(strPath, "Could not find warship%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}

	return TRUE;
}

// Load bullet ///////////////////////////////////////////////////////////////

BOOL CGameResource::LoadBullet(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < BULLET_COUNT; i++)
	{
		wsprintf(strPath, BULLET_PATH_DEBUG, i);
		if (!m_textureBullet[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, BULLET_PATH, i);
			if (!m_textureBullet[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find bullet%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load fireworks /////////////////////////////////////////////////////////

BOOL CGameResource::LoadFireworks(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < FIREWORKS_COUNT; i++)
	{
		wsprintf(strPath, FIREWORKS_PATH_DEBUG, i);
		if (!m_textureFireworks[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, FIREWORKS_PATH, i);
			if (!m_textureFireworks[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find fireworkst%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load bonus ////////////////////////////////////////////////////////////////

BOOL CGameResource::LoadBonus(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < BONUS_COUNT; i++)
	{
		wsprintf(strPath, BONUS_PATH_DEBUG, i);
		if (!m_textureBonus[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, BONUS_PATH, i);
			if (!m_textureBonus[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find bonus%d.dds!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Load state ////////////////////////////////////////////////////////////////

BOOL CGameResource::LoadState(LPDIRECT3DDEVICE9 &pDevice, DWORD inColorKey)
{
	char strPath[256];
	int i;
	for (i = 0; i < STATE_COUNT; i++)
	{
		wsprintf(strPath, STATE_PATH_DEBUG, i);
		if (!m_textureState[i].Create(pDevice, strPath, inColorKey))
		{
			// If can not find the picture, change path and retry
			wsprintf(strPath, STATE_PATH, i);
			if (!m_textureState[i].Create(pDevice, strPath, inColorKey))
			{
				wsprintf(strPath, "Could not find state%d.bmp!", i);
				MessageBox(NULL, strPath, "WARNING!", MB_ICONWARNING);
				return FALSE;
			}
		}
	}
	return TRUE;
}

// Release ///////////////////////////////////////////////////////////////////

void CGameResource::ReleaseSeaweed()
{
	m_textureSeaweed.Release();
}

void CGameResource::ReleaseSea()
{
	int i;
	for (i = 0; i < SEA_COUNT; i++)
	{
		m_textureSea[i].Release();
	}
}

void CGameResource::ReleaseIsland()
{
	int i;
	for (i = 0; i < ISLAND_COUNT; i++)
	{
		m_textureIsland[i].Release();
	}
}

void CGameResource::ReleaseWall()
{
	int i;
	for (i = 0; i < WALL_COUNT; i++)
	{
		m_textureWall[i].Release();
	}
}

void CGameResource::ReleaseReef()
{
	int i;
	for (i = 0; i < REEF_COUNT; i++)
	{
		m_textureReef[i].Release();
	}
}

void CGameResource::ReleaseBarbette()
{
	int i;
	for (i = 0; i < BARBETTE_COUNT; i++)
	{
		m_textureBarbette[i].Release();
	}
}

void CGameResource::ReleaseFense()
{
	int i;
	for (i = 0; i < FENSE_COUNT; i++)
	{
		m_textureFense[i].Release();
	}
}

void CGameResource::ReleaseWarship()
{
	int i;
	for (i = 0; i < WARSHIP_COUNT; i++)
	{
		m_textureWarship[i].Release();
	}
}

void CGameResource::ReleaseBullet()
{
	int i;
	for (i = 0; i < BULLET_COUNT; i++)
	{
		m_textureBullet[i].Release();
	}
}

void CGameResource::ReleaseFireworks()
{
	int i;
	for (i = 0; i < FIREWORKS_COUNT; i++)
	{
		m_textureFireworks[i].Release();
	}
}


void CGameResource::ReleaseBonus()
{
	int i;
	for (i = 0; i < BONUS_COUNT; i++)
	{
		m_textureBonus[i].Release();
	}
}

void CGameResource::ReleaseState()
{
	int i;
	for (i = 0; i < STATE_COUNT; i++)
	{
		m_textureState[i].Release();
	}
}

void CGameResource::ReleaseAll()
{
	ReleaseState();
	ReleaseBonus();
	ReleaseFireworks();
	ReleaseBullet();
	ReleaseWarship();
	ReleaseSeaweed();
	ReleaseFense();
	ReleaseBarbette();
	ReleaseReef();
	ReleaseWall();
	ReleaseIsland();
	ReleaseSea();
}

⌨️ 快捷键说明

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