?? role.cpp
字號:
ChangeState(new CRoleStateOnTrap(m_pRole));
}
else
{
ChangeState(new CRoleStateOnDismount(m_pRole));
}
}
}
void CRoleState::DrawShadow(int x, int y) const
{
m_pRole->m_bmShadow.DrawAlphaFast(SCREEN, x, y);
}
//-----------------------------------------------------------------------------
CRoleStateStart::CRoleStateStart(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
}
void CRoleStateStart::Draw(int x, int y) const
{
DrawShadow(x, y);
int nStartCol = 0;
if (m_nAniSeq < 24)
{
nStartCol = m_nAniSeq/2 % 4;
}
else if (m_nAniSeq == 24 || m_nAniSeq == 25)
{
nStartCol = 4;
}
else if (m_nAniSeq < 42)
{
nStartCol = (m_nAniSeq - 26)/2 % 4 + 5;
}
else if (m_nAniSeq < 58)
{
nStartCol = 9 - (m_nAniSeq - 42)/2 % 2;
}
else
{
nStartCol = 9 - m_nAniSeq % 2;
}
m_pRole->m_bmStart.Draw(SCREEN, x, y, nStartCol);
}
void CRoleStateStart::Update(float fDelta)
{
static const float DELTA_START = 0.03f;
static const int MAX_SEQ = 78;
m_fTime += fDelta;
if (m_fTime > DELTA_START)
{
m_fTime -= DELTA_START;
m_nAniSeq++;
if (m_nAniSeq == MAX_SEQ)
{
ChangeState(new CRoleStateNormal(m_pRole));
}
}
}
//-----------------------------------------------------------------------------
CRoleStateNormal::CRoleStateNormal(CRole *pRole)
: CRoleState(pRole)
, m_nIdleCount(0)
, m_nFrameCount(0)
, m_nCurrentFrame(0)
{
}
void CRoleStateNormal::Draw(int x, int y) const
{
DrawShadow(x, y);
if (m_pRole->m_Ability.Vehicle == vtNone)
{
m_pRole->m_bmMain.Draw(SCREEN, x, y, m_pRole->m_Direction, m_nCurrentFrame);
}
else
{
if (m_nCurrentFrame <= 3)
{
y += m_nCurrentFrame;
}
else
{
y += 6 - m_nCurrentFrame;
}
switch (m_pRole->m_Ability.Vehicle)
{
case vtSlowTurtle:
m_pRole->m_bmSlowTurtle.Draw(SCREEN, x, y, m_pRole->m_Direction, m_nCurrentFrame % 2);
m_pRole->m_bmRide.Draw(SCREEN, x, y, m_pRole->m_Direction);
break;
case vtFastTurtle:
m_pRole->m_bmFastTurtle.Draw(SCREEN, x, y, m_pRole->m_Direction, m_nCurrentFrame % 2);
m_pRole->m_bmRide.Draw(SCREEN, x, y, m_pRole->m_Direction);
break;
case vtOwl:
m_pRole->m_bmOwl.Draw(SCREEN, x, y, m_pRole->m_Direction, m_nCurrentFrame % 2);
m_pRole->m_bmRide.Draw(SCREEN, x, y, m_pRole->m_Direction);
break;
case vtFastUFO:
m_pRole->m_bmRide.Draw(SCREEN, x, y, m_pRole->m_Direction);
m_pRole->m_bmFastUFO.Draw(SCREEN, x, y, m_pRole->m_Direction, m_nCurrentFrame % 2);
break;
}
}
}
void CRoleStateNormal::Update(float fDelta)
{
if (m_pRole->m_bMoving)
{
m_nIdleCount = 0;
int nSpeed;
if (m_pRole->m_Ability.Vehicle != vtNone)
{
nSpeed = VEHICLE_SPEED[m_pRole->m_Ability.Vehicle];
}
else
{
nSpeed = m_pRole->m_Ability.nSpeed;
}
m_nFrameCount++;
if (m_nFrameCount > 10 / nSpeed)
{
m_nCurrentFrame = (m_nCurrentFrame+1) % 6;
m_nFrameCount = 0;
}
switch (m_pRole->m_Direction)
{
case drUp:
m_pRole->UpdateMoveUp(nSpeed);
break;
case drDown:
m_pRole->UpdateMoveDown(nSpeed);
break;
case drLeft:
m_pRole->UpdateMoveLeft(nSpeed);
break;
case drRight:
m_pRole->UpdateMoveRight(nSpeed);
break;
}
m_pRole->m_bMoving = false;
}
else
{
m_nCurrentFrame = 0;
m_pRole->m_nPushTime = 0;
if (m_pRole->m_Ability.Vehicle == vtNone)
{
m_nIdleCount++;
if (m_nIdleCount > 200)
{
m_nIdleCount = 0;
ChangeState(new CRoleStateIdle(m_pRole));
return;
}
}
}
CheckChange();
}
//-----------------------------------------------------------------------------
CRoleStateIdle::CRoleStateIdle(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
}
void CRoleStateIdle::Draw(int x, int y) const
{
DrawShadow(x, y);
if (m_nAniSeq <= 4)
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, m_nAniSeq % 2 + 6);
}
else
{
m_pRole->m_bmMain.Draw(SCREEN, x, y, drDown, 0);
}
}
void CRoleStateIdle::Update(float fDelta)
{
static const float DELTA_IDLE = 0.18f;
m_fTime += fDelta;
if (m_fTime > DELTA_IDLE)
{
m_fTime -= DELTA_IDLE;
m_nAniSeq = (m_nAniSeq + 1) % 25;
}
if (m_pRole->m_bMoving)
{
ChangeState(new CRoleStateNormal(m_pRole));
return;
}
CheckChange();
}
//-----------------------------------------------------------------------------
CRoleStateOnTrap::CRoleStateOnTrap(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
}
void CRoleStateOnTrap::Draw(int x, int y) const
{
DrawShadow(x, y);
m_pRole->m_bmAni.Draw(SCREEN, x, y, m_nAniSeq % 2);
m_pRole->m_bmBigPopo.DrawAlpha(SCREEN, x, y, 200, m_nAniSeq);
}
void CRoleStateOnTrap::Update(float fDelta)
{
static const float DELTA_ONTRAP = 0.1f;
m_fTime += fDelta;
if (m_fTime > DELTA_ONTRAP)
{
m_fTime -= DELTA_ONTRAP;
m_nAniSeq++;
if (m_nAniSeq == 3)
{
ChangeState(new CRoleStateTraped(m_pRole));
}
}
}
//-----------------------------------------------------------------------------
CRoleStateTraped::CRoleStateTraped(CRole *pRole)
: CRoleState(pRole)
, m_fTime(0.0f)
, m_fDeadTime(5.0f)
, m_nShake(0)
, m_nShakeDr(1)
, m_nSpeedCount(0)
{
}
void CRoleStateTraped::Draw(int x, int y) const
{
DrawShadow(x, y);
m_pRole->m_bmAni.Draw(SCREEN, x, y + m_nShake/2, m_nShake % 2);
if (m_fDeadTime > 1.0f)
{
m_pRole->m_bmBigPopo.DrawAlpha(SCREEN, x, y + m_nShake/2, 200, 3);
}
else
{
m_pRole->m_bmBigPopo.DrawAlpha(SCREEN, x, y + m_nShake/2,
255 - int(m_fDeadTime * 55), 3);
}
}
void CRoleStateTraped::Update(float fDelta)
{
static const float DELTA_SHAKE = 0.1f;
// 處理上下晃動
m_fTime += fDelta;
if (m_fTime > DELTA_SHAKE)
{
m_fTime -= DELTA_SHAKE;
m_nShake += m_nShakeDr;
if (m_nShake >= 12 || m_nShake <= 0)
{
m_nShakeDr = -m_nShakeDr;
}
}
// 處理死亡倒計時
m_fDeadTime -= fDelta;
if (m_fDeadTime <= 0.0f)
{
g_pGame->RoleOnDie(m_pRole);
ChangeState(new CRoleStateOnDie(m_pRole));
return;
}
// 處理運動
if (m_pRole->m_bMoving)
{
int nTrapedSpeed = m_nSpeedCount == 0 ? 1 : 0;
m_nSpeedCount = (m_nSpeedCount + 1) % 8;
switch (m_pRole->m_Direction)
{
case drUp:
m_pRole->UpdateMoveUp(nTrapedSpeed);
break;
case drDown:
m_pRole->UpdateMoveDown(nTrapedSpeed);
break;
case drLeft:
m_pRole->UpdateMoveLeft(nTrapedSpeed);
break;
case drRight:
m_pRole->UpdateMoveRight(nTrapedSpeed);
break;
}
}
m_pRole->m_nPushTime = 0;
m_pRole->m_bMoving = false;
// 檢測是否與其他主角相遇
for (int i = 0; i < ROLE_NUM; ++i)
{
if (&ROLE[i] != m_pRole && ROLE[i].GetX() == m_pRole->m_nCellX &&
ROLE[i].GetY() == m_pRole->m_nCellY)
{
ChangeState(new CRoleStateOnDie(m_pRole));
}
}
}
//-----------------------------------------------------------------------------
CRoleStateOnSave::CRoleStateOnSave(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
SOUND.Play(snSave);
}
void CRoleStateOnSave::Draw(int x, int y) const
{
DrawShadow(x, y);
if (m_nAniSeq != 3)
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 2);
}
else
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 3);
}
if (m_nAniSeq <= 2)
{
m_pRole->m_bmBigPopo.Draw(SCREEN, x, y, m_nAniSeq + 3);
}
}
void CRoleStateOnSave::Update(float fDelta)
{
static const float DELTA_ONSAVE = 0.1f;
m_fTime += fDelta;
if (m_fTime > DELTA_ONSAVE)
{
m_fTime -= DELTA_ONSAVE;
m_nAniSeq++;
if (m_nAniSeq == 5)
{
m_pRole->m_Direction = drDown;
ChangeState(new CRoleStateNormal(m_pRole));
}
}
}
//-----------------------------------------------------------------------------
CRoleStateOnDie::CRoleStateOnDie(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
m_pRole->m_bDead = true;
SOUND.Play(snDie);
}
void CRoleStateOnDie::Draw(int x, int y) const
{
DrawShadow(x, y);
if (m_nAniSeq < 9)
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 0);
m_pRole->m_bmBigPopo.Draw(SCREEN, x, y, 6 + m_nAniSeq / 3);
}
else if (m_nAniSeq < 32)
{
m_pRole->m_bmDie.Draw(SCREEN, x, y, (m_nAniSeq-9) / 4);
}
else if (m_nAniSeq < 36)
{
if (m_nAniSeq < 34)
{
m_pRole->m_bmDie.Draw(SCREEN, x, y, 6);
}
}
else if (m_nAniSeq < 60)
{
int nSeq = (m_nAniSeq - 36) / 2;
if (nSeq % 2 == 0)
{
m_pRole->m_bmDie.Draw(SCREEN, x, y, nSeq / 2 % 2 + 7);
}
}
else if (m_nAniSeq < 84)
{
int nSeq = (m_nAniSeq - 60) / 2;
if (nSeq % 2 == 0)
{
m_pRole->m_bmDie.Draw(SCREEN, x, y, nSeq / 2 % 2 + 9);
}
}
else
{
if (m_nAniSeq % 2 == 0)
{
m_pRole->m_bmDie.Draw(SCREEN, x, y, m_nAniSeq / 2 % 2 + 7);
}
}
}
void CRoleStateOnDie::Update(float fDelta)
{
static const float DELTA_ONDIE = 0.03f;
m_fTime += fDelta;
if (m_fTime > DELTA_ONDIE)
{
m_fTime -= DELTA_ONDIE;
m_nAniSeq++;
if (m_nAniSeq == 40)
{
g_pGame->RoleDead(m_pRole);
}
if (m_nAniSeq == 92)
{
ChangeState(new CRoleStateDead(m_pRole));
}
}
}
//-----------------------------------------------------------------------------
CRoleStateWin::CRoleStateWin(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
}
void CRoleStateWin::Draw(int x, int y) const
{
DrawShadow(x, y);
if (m_nAniSeq % 2 == 0)
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 2);
}
else if (m_nAniSeq == 1)
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 4);
}
else if (m_nAniSeq == 3)
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 5);
}
else
{
m_pRole->m_bmAni.Draw(SCREEN, x, y, 3);
}
}
void CRoleStateWin::Update(float fDelta)
{
static const float DELTA_WIN = 0.15f;
m_fTime += fDelta;
if (m_fTime > DELTA_WIN)
{
m_fTime -= DELTA_WIN;
m_nAniSeq = (m_nAniSeq + 1) % 16;
}
}
//-----------------------------------------------------------------------------
CRoleStateOnRide::CRoleStateOnRide(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
}
void CRoleStateOnRide::Draw(int x, int y) const
{
DrawShadow(x, y);
switch (m_pRole->m_Ability.Vehicle)
{
case vtSlowTurtle:
m_pRole->m_bmSlowTurtle.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
case vtFastTurtle:
m_pRole->m_bmFastTurtle.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
case vtOwl:
m_pRole->m_bmOwl.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
}
if (m_nAniSeq < 11)
{
m_pRole->m_bmRide.Draw(SCREEN, x, y - (m_nAniSeq - 4) * 3, m_pRole->m_Direction);
}
else
{
m_pRole->m_bmRide.Draw(SCREEN, x, y - (17 - m_nAniSeq) * 3, m_pRole->m_Direction);
}
switch (m_pRole->m_Ability.Vehicle)
{
case vtFastUFO:
m_pRole->m_bmFastUFO.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
case vtSlowUFO:
// 未實現(xiàn)
break;
}
}
void CRoleStateOnRide::Update(float fDelta)
{
static const float DELTA_ONRIDE = 0.025f;
m_fTime += fDelta;
if (m_fTime > DELTA_ONRIDE)
{
m_fTime -= DELTA_ONRIDE;
m_nAniSeq++;
if (m_nAniSeq > 17)
{
ChangeState(new CRoleStateNormal(m_pRole));
return;
}
}
}
//-----------------------------------------------------------------------------
CRoleStateOnDismount::CRoleStateOnDismount(CRole *pRole)
: CRoleState(pRole)
, m_nAniSeq(0)
, m_fTime(0.0f)
{
}
void CRoleStateOnDismount::Draw(int x, int y) const
{
DrawShadow(x, y);
if (m_nAniSeq <= 24 && m_nAniSeq/2 % 3 == 2)
{
switch (m_pRole->m_Ability.Vehicle)
{
case vtSlowTurtle:
m_pRole->m_bmSlowTurtle.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
case vtFastTurtle:
m_pRole->m_bmFastTurtle.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
case vtOwl:
m_pRole->m_bmOwl.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
}
}
if (m_nAniSeq < 12)
{
m_pRole->m_bmRide.Draw(SCREEN, x, y, m_pRole->m_Direction);
}
else if (m_nAniSeq < 24)
{
m_pRole->m_bmRide.Draw(SCREEN, x, y - (m_nAniSeq - 11) * 3, m_pRole->m_Direction);
}
else
{
m_pRole->m_bmRide.Draw(SCREEN, x, y - (36 - m_nAniSeq) * 3, m_pRole->m_Direction);
}
if (m_nAniSeq <= 24 && m_nAniSeq/2 % 3 == 2)
{
switch (m_pRole->m_Ability.Vehicle)
{
case vtFastUFO:
m_pRole->m_bmFastUFO.Draw(SCREEN, x, y, m_pRole->m_Direction, 0);
break;
case vtSlowUFO:
// 未實現(xiàn)
break;
}
}
}
void CRoleStateOnDismount::Update(float fDelta)
{
static const float DELTA_DISMOUNT = 0.025f;
m_fTime += fDelta;
if (m_fTime > DELTA_DISMOUNT)
{
m_fTime -= DELTA_DISMOUNT;
m_nAniSeq++;
if (m_nAniSeq > 40)
{
m_pRole->m_Ability.Vehicle = vtNone;
m_pRole->m_bFlying = false;
ChangeState(new CRoleStateNormal(m_pRole));
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -