// DXIsoMap.cpp: implementation of the CDXIsoMap class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DXIsoMap.h"
#include "DDDevice.h"
#include "DDDIBSurface.h"
#include "PackFile.h"
#include "IsoType.h"
//#include "stdafx.h"
//#include "Isotest.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
const CHAR CDXIsoMap::m_CellFigue[16][32] =
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2},
{1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2},
{1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4},
{3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4},
{3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,4,4,4,4,4,4,4,4,4,4,4,4,4,4},
{3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}
};
const int CDXIsoMap::m_nCellWidth = 32;
const int CDXIsoMap::m_nCellHeight = 16;
const int CDXIsoMap::m_nCellWidthShift = 5;
const int CDXIsoMap::m_nCellHeightShift = 4;
const BYTE CDXIsoMap::m_CellIdxFlg = 0x10;
const BYTE CDXIsoMap::m_CellRmrFlg = 0X20;
const BYTE CDXIsoMap::m_CellNpcFlg = 0x40;
const BYTE CDXIsoMap::m_CellLnkFlg = 0x80;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDXIsoMap::CDXIsoMap()
{
m_bAutoDelete = false;
m_pMapData = NULL;
m_nPosX = 0;
m_nPosY = 0;
m_nPosTX = 0;
m_nPosTY = 0;
m_nOffX = 0;
m_nOffY = 0;
m_pPassValues = NULL;
m_pTiles = NULL;
}
CDXIsoMap::~CDXIsoMap()
{
if (m_pPassValues != NULL)
{
delete []m_pPassValues;
m_pPassValues = NULL;
}
if (m_pMapData != NULL)
{
delete []m_pMapData;
m_pMapData = NULL;
}
if (m_bAutoDelete == true)
{
if (m_pTiles != NULL)
{
delete m_pTiles;
}
}
m_pTiles = NULL;
}
bool CDXIsoMap::Create(CDDSurface* pTiles,
LPCTSTR lpszFileName,
CPackFileManager* pPackFileManager/* = NULL*/)
{
ASSERT(pTiles != NULL);
ASSERT(lpszFileName != NULL);
int nCellColumns;
int nCellRows;
CELL* pMapData = NULL;
if (pPackFileManager != NULL) // use CPackFile
{
CPackFile packFile;
if (packFile.Open(pPackFileManager, lpszFileName) == false)
return false;
packFile.Read(&nCellColumns, sizeof(int));
packFile.Read(&nCellRows, sizeof(int));
int nSize = nCellColumns * nCellRows;
pMapData = new CELL[nSize];
ASSERT(pMapData != NULL);
packFile.Read(pMapData, sizeof(CELL) * nSize);
}
else
{
HANDLE fh = ::CreateFile(lpszFileName, GENERIC_READ,
FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE)
return false;
DWORD dwRead;
::ReadFile(fh, &nCellColumns, sizeof(int), &dwRead, NULL);
::ReadFile(fh, &nCellRows, sizeof(int), &dwRead, NULL);
int nSize = nCellColumns * nCellRows;
pMapData = new CELL[nSize];
ASSERT(pMapData != NULL);
::ReadFile(fh, pMapData, sizeof(CELL) * nSize, &dwRead, NULL);
::CloseHandle(fh);
}
return Create(pTiles,
nCellColumns, nCellRows,
pMapData);
}
bool CDXIsoMap::Save(LPCTSTR lpszFileName)
{
HANDLE fh = ::CreateFile(lpszFileName, GENERIC_WRITE,
0, (LPSECURITY_ATTRIBUTES)NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE)
return false;
DWORD dwWriteBytes;
::WriteFile(fh, &m_nColumns, sizeof(int), &dwWriteBytes, NULL);
::WriteFile(fh, &m_nRows, sizeof(int), &dwWriteBytes, NULL);
::WriteFile(fh, m_pMapData, sizeof(int) * m_nColumns * m_nRows, &dwWriteBytes, NULL);
::CloseHandle(fh);
return true;
}
bool CDXIsoMap::Create(CDDSurface* pTiles,
int nCellColumns, int nCellRows,
CELL* pMapData)
{
m_pTiles = pTiles;
m_nPosX = m_nCellWidth >> 1;
m_nPosY = m_nCellHeight >> 1;
m_nColumns = nCellColumns;
m_nRows = nCellRows;
m_nTotalWidth = m_nColumns << (m_nCellWidthShift - 1);
m_nTotalHeight = m_nRows << m_nCellHeightShift;
ASSERT(m_pMapData == NULL);
m_pMapData = pMapData;
m_nSrcSurfaceCellRows = (m_pTiles->GetWidth() / m_nCellWidth);
return true;
}
bool CDXIsoMap::Create(CDDSurface* pTiles,
int nCellColumns, int nCellRows, int nFill)
{
int nSize = nCellColumns * nCellRows;
CELL* pMapData = new CELL[nSize];
ASSERT(pMapData != NULL);
for (int i = 0; i < nSize; ++ i)
{
pMapData[i].base.index = (BYTE)nFill;
if (nFill & 0X100)
pMapData[i].base.flag = m_CellIdxFlg;
else pMapData[i].base.flag = 0;
pMapData[i].fringe.index = 0;
pMapData[i].fringe.flag = 0;
}
return Create(pTiles,
nCellColumns, nCellRows,
pMapData);
}
// 在屏幕的(nDestX, nDestY)位置画图块
// IN:
// nDestX
// nDestY: 屏幕坐标
void CDXIsoMap::BltTile(CDDSurface* pDestSurface,
int nDestX, int nDestY, CELL* pCell)
{
RECT drc, drc0;
drc.left = nDestX;
drc.top = nDestY;
drc.right = nDestX + m_nCellWidth;
drc.bottom = nDestY + m_nCellHeight;
if (IntersectRect(&drc0, &drc, &m_rcDest))
{
int nOffY = drc0.top - drc.top;
int nOffX = drc0.left - drc.left;
int nW = drc0.right - drc0.left;
int nH = drc0.bottom - drc0.top;
int nTileIndex = pCell->base.index;
if (pCell->base.flag & m_CellIdxFlg)
nTileIndex += 0x100;
int x1, y1;
RECT src;
if (nTileIndex)
{
x1 = (nTileIndex % m_nSrcSurfaceCellRows) << m_nCellWidthShift;
y1 = (nTileIndex / m_nSrcSurfaceCellRows) << m_nCellHeightShift;
src.top = y1 + nOffY;
src.left = x1 + nOffX;
src.bottom = src.top + nH;
src.right = src.left + nW;
m_pTiles->Draw(pDestSurface, drc0.left, drc0.top, &src);
}
nTileIndex = pCell->fringe.index;
if (pCell->fringe.flag & m_CellIdxFlg)
nTileIndex += 0x100;
if (nTileIndex)
{
x1 = (nTileIndex % m_nSrcSurfaceCellRows) << m_nCellWidthShift;
y1 = (nTileIndex / m_nSrcSurfaceCellRows) << m_nCellHeightShift;
src.top = y1 + nOffY;
src.left = x1 + nOffX;
src.bottom = src.top + nH;
src.right = src.left + nW;
m_pTiles->Draw(pDestSurface, drc0.left, drc0.top, &src);
}
}
}
void CDXIsoMap::SetViewRect(LPRECT lprcView)
{
ASSERT(lprcView != NULL);
m_rcDest.top = lprcView->top;
m_rcDest.left = lprcView->left;
m_rcDest.bottom = lprcView->bottom;
m_rcDest.right = lprcView->right;
}
void CDXIsoMap::Draw(CDDSurface* pDestSurface, LPRECT lprcDest)
{
if (lprcDest != NULL)
{
m_rcDest.top = lprcDest->top;
m_rcDest.left = lprcDest->left;
m_rcDest.bottom = lprcDest->bottom;
m_rcDest.right = lprcDest->right;
}
int nHalfW = m_nCellWidth >> 1;
int nHalfH = m_nCellHeight >> 1;
int nOffsetX;
int nOffsetY;
if (m_nPosTX & 1)
{
nOffsetX = (m_nPosX-nHalfW) & (m_nCellWidth-1);
nOffsetY = (m_nPosY-nHalfH) & (m_nCellHeight-1);
}
else
{
nOffsetX = m_nPosX & (m_nCellWidth-1);
nOffsetY = m_nPosY & (m_nCellHeight-1);
}
nOffsetX = -nOffsetX;
nOffsetY = -nOffsetY;
int nOffTx, nOffTy;
if (m_nPosTX & 1)
{
nOffTx = m_nPosTX - 1;
nOffTy = m_nPosTY;
nOffsetX = nOffsetX - nHalfW;
nOffsetY = nOffsetY - nHalfH;
}
else
{
nOffTx = m_nPosTX - 2;
nOff
GZM888888
- 粉丝: 514
- 资源: 3069
最新资源
- 同济大学作业之-LPC分析(男声变女声)和PCM编码
- java超市订单管理系统源码数据库 MySQL源码类型 WebForm
- 记录windows安装nvm:nvm-setup-2024-11-16.exe.zip
- 同济大学数字信号处理实验(包含实验报告)
- Kettle 是Kettle E.T.T.L. Envirnonment只取首字母的缩写,这意味着它被设计用来帮助你实现你的
- java微信小程序B2C商城 H5+APP源码 前后端分离数据库 MySQL源码类型 WebForm
- matplotlib 绘制随机漫步图
- java版快速开发框架后台管理系统源码数据库 MySQL源码类型 WebForm
- Java实现植物大战僵尸简易版
- matplotlib 绘制随机漫步图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈