📄 gameview.cpp
字号:
}
}
// 读出武器资源数据
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 1);
nCount = (int8)(czMapInfo[0]);
pGround += 1;
for (i = 0; i < nCount; i++)
{
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 1);
nIndex = (int8)(czMapInfo[0]);
pGround += 1;
for (j = 0; j < nIndex; j++)
{
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 3);
m_tPlayerWeapon[i][j].nResIndex = (int8)czMapInfo[0];
m_tPlayerWeapon[i][j].nSeekPosX = (int8)czMapInfo[1];
m_tPlayerWeapon[i][j].nSeekPosY = (int8)czMapInfo[2];
pGround += 3;
}
}
// 影子数据
MEMCPY(czMapInfo,(byte*)pGround, 1);
nCount = (int8)(czMapInfo[0]);// 几个动作图片
pGround += 1;
for (i = 0; i < nCount; i++)
{
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 4);
m_tPlayerShadow[i].nResIndex = (int8)czMapInfo[0];
m_tPlayerShadow[i].nSeekPosX = (int8)czMapInfo[1];
m_tPlayerShadow[i].nSeekPosY = (int8)czMapInfo[2];
m_tPlayerShadow[i].bTransform = (boolean)czMapInfo[3];
pGround += 4;
}
// 读出人物动作图片索引
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 1);
nCount = (int8)(czMapInfo[0]);
pGround += 1;
for (i = 0; i < nCount; i++)
{
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 1);
m_tPlayer.m_nPlayerDoingNum[i] = (int8)(czMapInfo[0]);
pGround += 1;
for (j = 0; j < m_tPlayer.m_nPlayerDoingNum[i]; j++)
{
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 3);
m_tPlayer.m_tPlayerIndex[i][j].nLeftIndex = (int8)czMapInfo[0];
m_tPlayer.m_tPlayerIndex[i][j].nRightIndex = (int8)czMapInfo[1];
m_tPlayer.m_nDoingTimeCount[i][j] = (int8)czMapInfo[2];
pGround += 3;
}
}
// 人物行动时的补足
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 1);
nCount = (int8)(czMapInfo[0]);
pGround += 1;
for (i = 0; i < nCount; i++)
{
MEMSET(czMapInfo, 0, 6);
MEMCPY(czMapInfo,(byte*)pGround, 2);
m_tPlayer.m_tPlayerBalance[i].nBalanceFun = (int8)czMapInfo[0];
m_tPlayer.m_tPlayerBalance[i].nBalanceX = (int8)czMapInfo[1];
pGround += 2;
}
ISHELL_FreeResData (((CGameApp*)GETAPPINSTANCE())->m_pIShell, pSource);
}
void CGameView::InitGameBmp()
{
int8 i = 0;
// 初始化缓存,存放地图位图
m_pScreen = IDISPLAY_GetDestination(((CGameApp*)GETAPPINSTANCE())->m_pIDisplay);
IBITMAP_CreateCompatibleBitmap(m_pScreen, &m_pbmDbd[0],
(uint16)200, (uint16)240);
m_pbmDbd[1] = LoadBmpResData(IDB_BOTTOMBG1);
m_pbmDbd[2] = LoadBmpResData(IDB_PLAYER);
m_pbmDbd[4] = LoadBmpResData(IDB_GAMEBG);
IBITMAP_CreateCompatibleBitmap(m_pScreen, &m_pbmDbd[3], (uint16)SPELLPLAYERBMP_WIDTH, (uint16)SPELLPLAYERBMP_HEIGHT);
IBITMAP_SetTransparencyColor(m_pbmDbd[0], m_pDoc->m_Color);
IBITMAP_SetTransparencyColor(m_pbmDbd[2], m_pDoc->m_Color);
IBITMAP_SetTransparencyColor(m_pbmDbd[3], m_pDoc->m_Color);
// BEGIN_CHECK
// {
// CHECK_NULL(m_pBitmap[BOTTOMBG_INDEX], CBitmap::CreateInstance());
// CHECK_NULL(m_pBitmap[PLAYER_INDEX], CBitmap::CreateInstance());
// }
// CATCH_CHECK
// {
// for (i = 0; i < 20; i++)
// {
// if (m_pBitmap[i])
// {
// CUSTOM_RELEASE(m_pBitmap[i]);
// m_pBitmap[i] = NULL;
// }
// }
// }
// END_CHECK
//
// if (LoadGameBmpRes())
// {
// // 先取原图存入内存
// for (i = 0; i < 2; i++)
// {
// IBITMAP_BltIn(m_pbmDbd[0], BACKGROUND_WIDTH*i, 0, BACKGROUND_WIDTH, 135,
// m_pBitmap[BOTTOMBG_INDEX]->m_pIBitmap, 0, 0, AEE_RO_COPY);
// }
// IBITMAP_BltIn(m_pbmDbd[1], 0, 0, 170, 30,
// m_pBitmap[PLAYER_INDEX]->m_pIBitmap, 0, 0, AEE_RO_COPY);
//
//// // 把背景画入缓冲
// DrawBgToBuffer();
//
// IBITMAP_SetTransparencyColor(m_pbmDbd[1], m_pDoc->m_Color);
// }
// else
// {
// for (i = 0; i < 20; i++)
// {
// if (m_pBitmap[i])
// {
// CUSTOM_RELEASE(m_pBitmap[i]);
// m_pBitmap[i] = NULL;
// }
// }
//
// // 释放资源
// for (int i = 0; i < 40; i++)
// {
// if (m_pbmDbd[i])
// {
// IBITMAP_Release(m_pbmDbd[i]);
// m_pbmDbd[i] = NULL;
// }
// }
// if (m_pScreen)
// {
// IBITMAP_Release(m_pScreen);
// m_pScreen = NULL;
// }
// }
}
//bool CGameView::LoadGameBmpRes()
//{
// int8 i = 0;
//
// BEGIN_CHECK
// {
// CHECK_ERROR(m_pBitmap[BOTTOMBG_INDEX]->Load(IDB_BOTTOMBG1 + m_nGameStage-1));
// CHECK_ERROR(m_pBitmap[PLAYER_INDEX]->Load(IDB_PLAYER));
// }
// CATCH_CHECK
// {
// for (i = 0; i < 20; i++)
// {
// if (m_pBitmap[i])
// {
// CUSTOM_RELEASE(m_pBitmap[i]);
// m_pBitmap[i] = NULL;
// }
// }
// return false;
// }
//
// return true;
//}
void CGameView::DrawBgToBuffer()
{
// int8 i = 0;
//
// AEERect rect;
// rect.x = 0;
// rect.y = 0;
// rect.dx = BACKGROUND_WIDTH * 3;
// rect.dy = 135;
// IBITMAP_FillRect(m_pbmDbd[2], &rect, m_pDoc->m_Color, AEE_RO_COPY);
//
// // 准备拼图,每一行一个循环
// for (i = 0; i < m_nMapElementNum; i++)
// {
// if (m_tMapBg[i].nStatus == 0)
// IBITMAP_BltIn(m_pbmDbd[2], m_tMapBg[i].nMapPosX, m_tMapBg[i].nMapPosY,
// m_tMapBg[i].nIndexWidth, m_tMapBg[i].nIndexHeight, m_pbmDbd[1],
// m_tMapBg[i].nMapIndexX, m_tMapBg[i].nMapIndexY, AEE_RO_TRANSPARENT);
// }
//
// // 画水背景缓冲
// for (i = 0; i < 16; i++)
// IBITMAP_BltIn(m_pbmDbd[3], 22*i, 0, 22, 70, m_pbmDbd[1], 0, 0, AEE_RO_TRANSPARENT);
}
//int16 CGameView::GetRandomData(int16 nStart, int16 nEnd)
//{
// int16 n1 = nStart;
// int16 n2 = nEnd;
// uint8 n;
//
// while (true)
// {
// GETRAND((byte* )&n, sizeof(uint8));
// n = n % n2;
// if (n >= n1 && n < n2)
// return n;
// }
//
// return 0;
//}
void CGameView::DrawGameBmp()
{
int8 i = 0;
// 画移动背景
DrawMovingBg();
for (i = 0; i < 40; i++)
{
if (m_pCharacter[i] && m_pCharacter[i]->m_nDataStatus == 0)
{
switch (m_pCharacter[i]->nType)
{
case 0:
((CPlayer* )m_pCharacter[i])->Draw();
break;
// case 1:
// ((CEnemy* )m_pCharacter[i])->Draw();
// break;
// case 2:
// ((CBalk* )m_pCharacter[i])->Draw();//m_pCharacter[i]);
// break;
// case 3:
// ((CBoss* )m_pCharacter[i])->Draw();//DrawBoss(m_pCharacter[i]);
// break;
default:
break;
}
}
}
if (m_nCurGameStatus == 0 || m_nCurGameStatus == 2)
{
IGRAPHICS_DrawRect(m_pIGraphics, &m_tRect[0]);
IGRAPHICS_DrawRect(m_pIGraphics, &m_tRect[1]);
}
IDISPLAY_Update (((CGameApp*)GETAPPINSTANCE())->m_pIDisplay);
}
void CGameView::DrawMovingBg()
{
int nMapXIndex = m_nMapX / SIGLE_MAP_WIDTH;
int nMapPosX = m_nMapX % SIGLE_MAP_WIDTH;
int nMapYIndex = m_nMapY / SIGLE_MAP_WIDTH;
int nMapPosY = m_nMapY % SIGLE_MAP_WIDTH;
if (nMapPosY == -1)
int8 iii = 0;
int nRowIndex = 0;
int nColIndex = 0;
AEERect tRect;
tRect.x = 0;
tRect.y = 0;
tRect.dx = 220;
tRect.dy = 240;
IBITMAP_FillRect(m_pbmDbd[0], &tRect, m_pDoc->m_Color, AEE_RO_COPY);
// 准备拼图,每一行一个循环
for (int8 nRow = 0; nRow < 12; nRow++)
{
if (nMapYIndex+nRow < 0 || nMapYIndex+nRow >= m_nMapHeight)
continue;
for (int8 nCol = 0; nCol < 10; nCol++)
{
if (nMapXIndex+nCol < 0 || nMapXIndex+nCol >= m_nMapWidth)
continue;
int8 nMapType = m_pMap[(nMapYIndex+nRow)*m_nMapWidth + (nCol+nMapXIndex)];
IBITMAP_BltIn(m_pbmDbd[0], nCol * 20, nRow * 20,
20, 20, m_pbmDbd[1],
m_tMapElement[nMapType-1].nPosX,
m_tMapElement[nMapType-1].nPosY, AEE_RO_COPY);
}
}
IBITMAP_BltIn(m_pScreen, 0, 0, 176, 205, m_pbmDbd[4],
0, 0, AEE_RO_COPY);
// 画底层移动背景
IBITMAP_BltIn(m_pScreen, 0, 0, 176, 205, m_pbmDbd[0],
nMapPosX, nMapPosY, AEE_RO_TRANSPARENT);
}
void CGameView::UpdateGameData()
{
// 处理关卡变化
int8 i = 0;
for (i = 0; i < m_nChangeStageNum; i++)
{
if ((m_tPlayer.m_nRelativePosX > m_tChangeStage[i].nStartMapX && m_tPlayer.m_nRelativePosX < m_tChangeStage[i].nEndMapX)
&& m_tPlayer.m_nRelativePosY == m_tChangeStage[i].nMapY)
{
m_nChangeIndex = i;
m_nCurGameStatus = 2;
m_nGameWorld = m_tChangeStage[i].nChangeWorld;
m_nGameStage = m_tChangeStage[i].nChangeStage;
InitGameGraphics();
return;
}
}
m_tPlayer.UpdatePlayerData();
}
boolean CGameView::Moveable(int16 nPosX, int16 nPosY)
{
//取得当前障碍元素
int8 nMapElement = 0;
int nLineX = nPosX / SIGLE_MAP_WIDTH;
int nLineY = nPosY / SIGLE_MAP_HEIGHT * MAP_COL_INDEX;
if (nLineX < 0 || nLineY < 0)
return TRUE;
nMapElement = (int8)m_pMap[nLineX+nLineY];
return m_tMapElement[nMapElement-1].bBlock;
}
void CGameView::TransformBmp(IBitmap* pDestBmp, int16 nDestPosX, int16 nDestPosY,
IBitmap* pSrcBmp, int16 nSrcPosX, int16 nSrcPosY, int8 nSrcWidth, int8 nSrcHeight)
{
// int16 nStartX = nSrcStartX;
ITransform* pTransform = NULL;
IBITMAP_QueryInterface(pDestBmp, AEECLSID_TRANSFORM,
(void** )&pTransform);
ITRANSFORM_TransformBltSimple(pTransform, nDestPosX, nDestPosY, pSrcBmp, nSrcPosX, nSrcPosY, nSrcWidth, nSrcHeight,
TRANSFORM_FLIP_X | TRANSFORM_ROTATE_180,COMPOSITE_KEYCOLOR);
if (pTransform != NULL)
{
ITRANSFORM_Release(pTransform);
pTransform = NULL;
}
}
void CGameView::UpdateStartGame()
{
m_tRect[0].x -= 4;
m_tRect[1].x += 4;
if (m_tRect[0].x <= -88)
{
m_nCurGameStatus = 1;
IGRAPHICS_Release(m_pIGraphics);
m_pIGraphics = NULL;
}
m_tPlayer.UpdatePlayerData();
}
void CGameView::InitGameGraphics()
{
CGameApp* pApp = (CGameApp*)GETAPPINSTANCE();
if (m_pIGraphics != NULL)
{
IGRAPHICS_Release(m_pIGraphics);
m_pIGraphics = NULL;
}
if (m_pIGraphics == NULL)
{
ISHELL_CreateInstance(pApp->m_pIShell, AEECLSID_GRAPHICS, (void**)&m_pIGraphics);
if (m_pIGraphics == NULL)
return;
IGRAPHICS_SetFillColor(m_pIGraphics, 0, 0, 0, 0);
IGRAPHICS_SetFillMode(m_pIGraphics, TRUE);
}
if (m_nCurGameStatus == 0)
{
m_tRect[0].x = 4;
m_tRect[0].y = 0;
m_tRect[0].dx = 88;
m_tRect[0].dy = 205;
m_tRect[1].x = 84;
m_tRect[1].y = 0;
m_tRect[1].dx = 88;
m_tRect[1].dy = 205;
}
else if (m_nCurGameStatus == 2)
{
m_tRect[0].x = -88;
m_tRect[0].y = 0;
m_tRect[0].dx = 88;
m_tRect[0].dy = 205;
m_tRect[1].x = 176;
m_tRect[1].y = 0;
m_tRect[1].dx = 88;
m_tRect[1].dy = 205;
}
}
void CGameView::UpdateEndGame()
{
m_tRect[0].x += 4;
m_tRect[1].x -= 4;
if (m_tRect[0].x >= 4)
{
IGRAPHICS_Release(m_pIGraphics);
m_pIGraphics = NULL;
m_nCurGameStatus = 0;
m_nMapX = m_tStageData[m_nChangeIndex].nMapX;
m_nMapY = m_tStageData[m_nChangeIndex].nMapY;
m_tPlayer.m_nRelativePosX = m_tStageData[m_nChangeIndex].nRelativePosX;
m_tPlayer.m_nRelativePosY = m_tStageData[m_nChangeIndex].nRelativePosY;
m_tPlayer.m_nPosX = m_tStageData[m_nChangeIndex].nPosX;
m_tPlayer.m_nPosY = m_tStageData[m_nChangeIndex].nPosY;
m_tPlayer.m_nCurFaceX = m_tStageData[m_nChangeIndex].nCurFaceX;
ReleaseBmpRes();
InitGameData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -