diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 340296627..50911896f 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -170,16 +170,26 @@ void AnimationInfo::ChangeAnimationData(CelSprite *pCelSprite, int numberOfFrame DelayLen = delayLen; } -void AnimationInfo::ProcessAnimation() +void AnimationInfo::ProcessAnimation(bool reverseAnimation /*= false*/, bool dontProgressAnimation /*= false*/) { DelayCounter++; + if (dontProgressAnimation) + return; TicksSinceSequenceStarted++; if (DelayCounter > DelayLen) { DelayCounter = 0; - CurrentFrame++; - if (CurrentFrame > NumberOfFrames) { - CurrentFrame = 1; - TicksSinceSequenceStarted = 0; + if (reverseAnimation) { + CurrentFrame--; + if (CurrentFrame == 0) { + CurrentFrame = NumberOfFrames; + TicksSinceSequenceStarted = 0; + } + } else { + CurrentFrame++; + if (CurrentFrame > NumberOfFrames) { + CurrentFrame = 1; + TicksSinceSequenceStarted = 0; + } } } } diff --git a/Source/engine/animationinfo.h b/Source/engine/animationinfo.h index e435b9052..3f17da79c 100644 --- a/Source/engine/animationinfo.h +++ b/Source/engine/animationinfo.h @@ -89,8 +89,10 @@ public: /* * @brief Process the Animation for a game tick (for example advances the frame) + * @param reverseAnimation Play the animation backwards (for example is used for "unseen" monster fading) + * @param dontProgressAnimation Increase DelayCounter but don't change CurrentFrame */ - void ProcessAnimation(); + void ProcessAnimation(bool reverseAnimation = false, bool dontProgressAnimation = false); private: /** diff --git a/Source/monster.cpp b/Source/monster.cpp index d368a9fdd..d52d0f10b 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1268,11 +1268,8 @@ void monster_43C785(int i) void NewMonsterAnim(int i, AnimStruct *anim, Direction md) { MonsterStruct *Monst = &monster[i]; - Monst->AnimInfo.pCelSprite = &*anim->CelSpritesForDirections[md]; - Monst->AnimInfo.NumberOfFrames = anim->Frames; - Monst->AnimInfo.DelayCounter = 0; - Monst->AnimInfo.CurrentFrame = 1; - Monst->AnimInfo.DelayLen = anim->Rate; + auto *pCelSprite = &*anim->CelSpritesForDirections[md]; + Monst->AnimInfo.SetNewAnimation(pCelSprite, anim->Frames, anim->Rate); Monst->_mFlags &= ~(MFLAG_LOCK_ANIMATION | MFLAG_ALLOW_SPECIAL); Monst->_mdir = md; } @@ -4624,21 +4621,7 @@ void ProcessMonsters() } } while (raflag); if (Monst->_mmode != MM_STONE) { - Monst->AnimInfo.DelayCounter++; - if (!(Monst->_mFlags & MFLAG_ALLOW_SPECIAL) && Monst->AnimInfo.DelayCounter >= Monst->AnimInfo.DelayLen) { - Monst->AnimInfo.DelayCounter = 0; - if (Monst->_mFlags & MFLAG_LOCK_ANIMATION) { - Monst->AnimInfo.CurrentFrame--; - if (Monst->AnimInfo.CurrentFrame == 0) { - Monst->AnimInfo.CurrentFrame = Monst->AnimInfo.NumberOfFrames; - } - } else { - Monst->AnimInfo.CurrentFrame++; - if (Monst->AnimInfo.CurrentFrame > Monst->AnimInfo.NumberOfFrames) { - Monst->AnimInfo.CurrentFrame = 1; - } - } - } + Monst->AnimInfo.ProcessAnimation(Monst->_mFlags & MFLAG_LOCK_ANIMATION, Monst->_mFlags & MFLAG_ALLOW_SPECIAL); } } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index d952312a3..e59eaadcb 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -320,7 +320,7 @@ static void DrawMonster(const CelOutputBuffer &out, int x, int y, int mx, int my return; } - int nCel = monster[m].AnimInfo.CurrentFrame; + int nCel = monster[m].AnimInfo.GetFrameToUseForRendering(); auto frameTable = reinterpret_cast(monster[m].AnimInfo.pCelSprite->Data()); int frames = SDL_SwapLE32(frameTable[0]); if (nCel < 1 || frames > 50 || nCel > frames) { @@ -701,7 +701,7 @@ static void DrawMonsterHelper(const CelOutputBuffer &out, int x, int y, int oy, px = sx + pMonster->position.offset.x - CalculateWidth2(cel.Width()); py = sy + pMonster->position.offset.y; if (mi == pcursmonst) { - Cl2DrawOutline(out, 233, px, py, cel, pMonster->AnimInfo.CurrentFrame); + Cl2DrawOutline(out, 233, px, py, cel, pMonster->AnimInfo.GetFrameToUseForRendering()); } DrawMonster(out, x, y, px, py, mi); }