📄 player.cpp
字号:
// Player.cpp: implementation of the CPlayer class.
//
//////////////////////////////////////////////////////////////////////
#include "Player.h"
#include "GameView.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPlayer::CPlayer()
{
}
CPlayer::~CPlayer()
{
}
void CPlayer::Draw()
{
SpellPlayerBmp();
DrawPlayer(m_pGameView->m_pbmDbd[3]);
}
void CPlayer::SpellPlayerBmp()
{
AEERect tRect;
tRect.x = 0;
tRect.y = 0;
tRect.dx = SPELLPLAYERBMP_WIDTH;
tRect.dy = SPELLPLAYERBMP_HEIGHT;
IBITMAP_FillRect(m_pGameView->m_pbmDbd[3], &tRect, m_pGameView->m_pDoc->m_Color, AEE_RO_COPY);
// 拼人物动作
for (int8 i = 0; i < m_pGameView->m_nActionBmpNum[m_nCurIndex]; i++)
{
if (m_pGameView->m_tPlayerAction[m_nCurIndex][i].bTransform == FALSE)
IBITMAP_BltIn(m_pGameView->m_pbmDbd[3], m_pGameView->m_tPlayerAction[m_nCurIndex][i].nSeekPosX,
SPELLPLAYERBMP_HEIGHT-m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResHeight
-m_pGameView->m_tPlayerAction[m_nCurIndex][i].nSeekPosY,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResWidth,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResHeight,
m_pGameView->m_pbmDbd[2],
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResPosX,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResPosY, AEE_RO_TRANSPARENT);
else// 翻转
m_pGameView->TransformBmp(m_pGameView->m_pbmDbd[3], m_pGameView->m_tPlayerAction[m_nCurIndex][i].nSeekPosX,
SPELLPLAYERBMP_HEIGHT-m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResHeight
-m_pGameView->m_tPlayerAction[m_nCurIndex][i].nSeekPosY, m_pGameView->m_pbmDbd[2],
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResPosX,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResPosY,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResWidth,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerAction[m_nCurIndex][i].nResIndex].nResHeight);
}
// 画刀光
if (m_nCurDoing == 5)
{
if (m_pGameView->m_tPlayerAction[m_nCurIndex][0].bTransform == FALSE)
IBITMAP_BltIn(m_pGameView->m_pbmDbd[3], m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nSeekPosX,
SPELLPLAYERBMP_HEIGHT-m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nResIndex].nResHeight
-m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nSeekPosY,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nResIndex].nResWidth,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nResIndex].nResHeight,
m_pGameView->m_pbmDbd[2],
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nResIndex].nResPosX,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2].nResIndex].nResPosY, AEE_RO_TRANSPARENT);
else// 翻转
m_pGameView->TransformBmp(m_pGameView->m_pbmDbd[3], m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nSeekPosX,
SPELLPLAYERBMP_HEIGHT-m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nResIndex].nResHeight
-m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nSeekPosY, m_pGameView->m_pbmDbd[2],
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nResIndex].nResPosX,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nResIndex].nResPosY,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nResIndex].nResWidth,
m_pGameView->m_tBmpData[m_pGameView->m_tPlayerWeapon[m_nCurWeaponType][m_nCurDoingNum*2+1].nResIndex].nResHeight);
}
}
void CPlayer::DrawPlayer(IBitmap* pbm)
{
int8 i = 0;
int8 nBalanceX = (m_tPlayerBalance[m_nCurIndex].nBalanceFun == 1)?
(-m_tPlayerBalance[m_nCurIndex].nBalanceX):(m_tPlayerBalance[m_nCurIndex].nBalanceX);
// 画影子
// if ((m_nCurDoing < 2 || m_nCurDoing > 4) || (m_nCurDoing == 2 && m_nCurDirectY == 0))
// {
// if (m_pGameView->m_tPlayerShadow[m_nCurIndex].bTransform == FALSE)
// IBITMAP_BltIn(m_pGameView->m_pScreen, m_nPosX+m_pGameView->m_tPlayerShadow[m_nCurIndex].nSeekPosX+nBalanceX,
// m_nRelativePosY-m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResHeight
// -m_pGameView->m_tPlayerShadow[m_nCurIndex].nSeekPosY,
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResWidth,
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResHeight,
// m_pGameView->m_pbmDbd[2],
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResPosX,
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResPosY, AEE_RO_TRANSPARENT);
// else
// m_pGameView->TransformBmp(m_pGameView->m_pScreen, m_nRelativePosX+m_pGameView->m_tPlayerShadow[m_nCurIndex].nSeekPosX+nBalanceX,
// m_nRelativePosY-m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResHeight
// -m_pGameView->m_tPlayerShadow[m_nCurIndex].nSeekPosY, m_pGameView->m_pbmDbd[2],
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResPosX,
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResPosY,
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResWidth,
// m_pGameView->m_tBmpData[m_pGameView->m_tPlayerShadow[m_nCurIndex].nResIndex].nResHeight);
// }
if (m_pGameView->m_tPlayerShadow[m_nCurIndex].bTransform == FALSE)
IBITMAP_BltIn(m_pGameView->m_pScreen, m_tShadow.nPosX+nBalanceX,
m_tShadow.nPosY-m_pGameView->m_tBmpData[m_tShadow.nIndex].nResHeight
-m_pGameView->m_tPlayerShadow[m_nCurIndex].nSeekPosY,
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResWidth,
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResHeight,
m_pGameView->m_pbmDbd[2],
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResPosX,
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResPosY, AEE_RO_TRANSPARENT);
else
m_pGameView->TransformBmp(m_pGameView->m_pScreen,m_tShadow.nPosX+nBalanceX,
m_tShadow.nPosY-m_pGameView->m_tBmpData[m_tShadow.nIndex].nResHeight
-m_pGameView->m_tPlayerShadow[m_nCurIndex].nSeekPosY, m_pGameView->m_pbmDbd[2],
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResPosX,
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResPosY,
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResWidth,
m_pGameView->m_tBmpData[m_tShadow.nIndex].nResHeight);
// IBITMAP_BltIn(m_pGameView->m_pScreen, m_nPosX+nBalanceX, m_nPosY-SPELLPLAYERBMP_HEIGHT,
// SPELLPLAYERBMP_WIDTH, SPELLPLAYERBMP_HEIGHT, pbm, 0, 0, AEE_RO_TRANSPARENT);
AEERect tRect;
tRect.x = 0;
tRect.y = 0;
tRect.dx = SPELLPLAYERBMP_WIDTH;
tRect.dy = SPELLPLAYERBMP_HEIGHT;
DrawShapeTrans(((CGameApp*)GETAPPINSTANCE())->m_pIDisplay, &tRect, pbm, m_pGameView->m_pDoc->m_Color);
}
void CPlayer::UpdatePlayerData()
{
int8 nBalanceX = 28;// 人物移动的横向补足
boolean bMoveX = TRUE;
boolean bMoveY = TRUE;
int8 i = 0;
int8 nRunDistanceY = 0;
int8 nRunDistanceX = 0;
int8 nDistanceY = 0;
int8 nDistanceX = 0;
switch (m_nCurDoing)
{
case 0:// 站立
{
nRunDistanceY = WORLD_ACCELERATION/ 2;
for (i = 0; i < 3; i++)//宽度28
{
int tt = i*SIGLE_MAP_WIDTH;
if (i == 0)
tt = 2;
else if (i == 2)
tt = 26;
bMoveY = m_pGameView->Moveable(m_nRelativePosX+tt, (m_nRelativePosY+1)+nRunDistanceY);
if (bMoveY == FALSE)
break;
}
if (bMoveY)
{
m_nCurDoing = 4;
m_nCurDoingNum = 0;
m_nDoingTimeNum = 0;
m_nRunSpeedY = 0;
m_nRunTime = 1;
m_nRunDistanceY = 0;
break;
}
// 处理人物图
if (m_nDoingTimeNum < m_nDoingTimeCount[m_nCurDoing][m_nCurDoingNum])
m_nDoingTimeNum++;
else
{
if (m_nCurDoingNum < m_nPlayerDoingNum[m_nCurDoing]-1)
m_nCurDoingNum++;
else
m_nCurDoingNum = 0;
m_nDoingTimeNum = 0;
}
}
break;
case 1:// 移动
{
// 处理转身
if (m_nCurFaceX != m_nCurDirectX)
{
m_nCurFaceX = m_nCurDirectX;
m_pGameView->m_tPlayer.m_nCurDoingNum = 0;
m_pGameView->m_tPlayer.m_nDoingTimeNum = 0;
m_pGameView->m_tPlayer.m_nRunSpeedY = 0;
m_pGameView->m_tPlayer.m_nRunTime = 0;
break;;
}
nRunDistanceY = WORLD_ACCELERATION/ 2;
for (i = 0; i < 3; i++)//宽度28
{
int tt = i*SIGLE_MAP_WIDTH;
if (i == 0)
tt = 2;
else if (i == 2)
tt = 26;
bMoveY = m_pGameView->Moveable(m_nRelativePosX+tt, (m_nRelativePosY+1)+nRunDistanceY);
if (bMoveY == FALSE)
break;
}
if (bMoveY)
{
m_nCurDoing = 4;
m_nCurDoingNum = 0;
m_nDoingTimeNum = 0;
m_nRunSpeedY = 0;
m_nRunTime = 1;
m_nRunDistanceY = 0;
break;
}
nBalanceX = (m_nCurDirectX == 0)?0:28;
m_nRunSpeedX = (m_nCurDirectX == 0)?(-PLAYER_MOVEX):(PLAYER_MOVEX);
for (i = 0; i < 4; i++)//高度49
{
int tt = i*SIGLE_MAP_HEIGHT;
if (i == 3)
tt = 49;
bMoveX = m_pGameView->Moveable(m_nRelativePosX+nBalanceX+m_nRunSpeedX, m_nRelativePosY-tt);
if (bMoveX == FALSE)
break;
}
if (bMoveX)
{
if ((m_nCurDirectX == 0 && m_pGameView->m_nMapX < PLAYER_MOVEX)
|| (m_nCurDirectX == 1 && (m_pGameView->m_nMapX+BACKGROUND_WIDTH > (MAP_COL_INDEX*SIGLE_MAP_WIDTH-PLAYER_MOVEX))))
{
if (m_nCurDirectX == 0 && m_nPosX >= PLAYER_MOVEX)
{
m_nRelativePosX += m_nRunSpeedX;
m_nPosX += m_nRunSpeedX;
}
else if (m_nCurDirectX == 1 && m_nPosX+27 <= BACKGROUND_WIDTH - PLAYER_MOVEX)
{
m_nRelativePosX += m_nRunSpeedX;
m_nPosX += m_nRunSpeedX;
}
}
else
{
if ((m_nCurDirectX == 1 && m_nPosX <= (INIT_POSX-3)) || (m_nCurDirectX == 0 && m_nPosX >= (INIT_POSX+3)))
{
m_nRelativePosX += m_nRunSpeedX;
m_nPosX += m_nRunSpeedX;
}
else
{
m_pGameView->m_nMapX += m_nRunSpeedX;
m_nRelativePosX += m_nRunSpeedX;
}
}
}
else
{
}
if (m_nDoingTimeNum < m_nDoingTimeCount[m_nCurDoing][m_nCurDoingNum])
m_nDoingTimeNum++;
else
{
if (m_nCurDoingNum < m_nPlayerDoingNum[m_nCurDoing]-1)
m_nCurDoingNum++;
else
m_nCurDoingNum = 0;
m_nDoingTimeNum = 0;
}
}
break;
case 2:// 跳跃
{
HandleJump();
// 处理人物图
if (m_nDoingTimeNum < m_nDoingTimeCount[m_nCurDoing][m_nCurDoingNum])
m_nDoingTimeNum++;
// if (m_nDoingTimeNum >= m_nDoingTimeCount[m_nCurDoing][m_nCurDoingNum])
else
{
if (m_nCurDoingNum < m_nPlayerDoingNum[m_nCurDoing]-1)
m_nCurDoingNum++;
else
m_nCurDoingNum = 0;
m_nDoingTimeNum = 0;
}
}
break;
case 3:// 空中平移
{
if (m_nRunSpeedX <= 0)
{
m_nCurDoing = 0;
m_nCurDoingNum = 0;
m_nDoingTimeNum = 0;
m_nRunDistanceX = 0;
break;
}
nBalanceX = (m_nCurDirectX == 0)?0:28;
nRunDistanceX = m_nRunSpeedX*m_nRunTime+(WORLD_ACCELERATION*m_nRunTime*m_nRunTime)/2;
nDistanceX = nRunDistanceX-m_nRunDistanceX;
m_nRunDistanceX += nDistanceX;
nDistanceX = (m_nCurDirectX == 0)?(-nDistanceX):(nDistanceX);
for (i = 0; i < 4; i++)//高度49
{
int tt = i*SIGLE_MAP_HEIGHT;
if (i == 3)
tt = 49;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -