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

📄 gameresource.cpp

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

#include "stdafx.h"
//#include <windows.h>
#include "MapEdit.h"
#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";

// 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);
	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;
}

// 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::ReleaseAll()
{
	ReleaseSeaweed();
	ReleaseFense();
	ReleaseBarbette();
	ReleaseReef();
	ReleaseWall();
	ReleaseIsland();
	ReleaseSea();
}

⌨️ 快捷键说明

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