diff --git a/Adventures in Lestoria/Boar.cpp b/Adventures in Lestoria/Boar.cpp index b6eb86d4..95be42c6 100644 --- a/Adventures in Lestoria/Boar.cpp +++ b/Adventures in Lestoria/Boar.cpp @@ -46,6 +46,7 @@ If range to player<400 backpaddle with 50% move-spd. if getting hit while backpa */ INCLUDE_game +INCLUDE_ANIMATION_DATA using A=Attribute; void Monster::STRATEGY::BOAR(Monster&m,float fElapsedTime,std::string strategy){ @@ -67,11 +68,15 @@ void Monster::STRATEGY::BOAR(Monster&m,float fElapsedTime,std::string strategy){ m.AddBuff(BuffType::SLOWDOWN,INFINITE,(100-ConfigInt("Backpedal Movespeed"))/100.f); RUN_AWAY(m,fElapsedTime,"Run Away"); m.UpdateFacingDirection(game->GetPlayer()->GetPos()); - }else m.phase=PhaseName::SCRATCH; + }else{ + m.PerformOtherAnimation(0); + m.F(A::CASTING_TIMER)=m.GetCurrentAnimation().GetTotalAnimationDuration(); + m.phase=PhaseName::SCRATCH; + } }break; case PhaseName::SCRATCH:{ m.RemoveBuff(BuffType::SLOWDOWN); - + }break; case PhaseName::CHARGE:{ diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index 78b67796..5c0709ae 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -845,4 +845,8 @@ const bool Monster::IsNPC()const{ const bool MonsterData::IsNPC()const{ return isNPC; +} + +const Animate2D::FrameSequence&Monster::GetCurrentAnimation()const{ + return ANIMATION_DATA[animation.currentStateName]; } \ No newline at end of file diff --git a/Adventures in Lestoria/Monster.h b/Adventures in Lestoria/Monster.h index 95d3dd6d..da4752d8 100644 --- a/Adventures in Lestoria/Monster.h +++ b/Adventures in Lestoria/Monster.h @@ -109,6 +109,7 @@ public: void PerformNPCLeftAnimation(); void PerformNPCRightAnimation(); void PerformOtherAnimation(const uint8_t otherInd); + const Animate2D::FrameSequence&GetCurrentAnimation()const; bool OnUpperLevel(); void Moved(); //Returns false if a path could not be found. diff --git a/Adventures in Lestoria/MonsterAttribute.h b/Adventures in Lestoria/MonsterAttribute.h index 2e4db660..dd91afc2 100644 --- a/Adventures in Lestoria/MonsterAttribute.h +++ b/Adventures in Lestoria/MonsterAttribute.h @@ -107,5 +107,4 @@ enum class Attribute{ LAST_JUMP_TIMER, INITIALIZED, JUMP_MOVE_TO_TARGET_TIMER, - }; \ No newline at end of file diff --git a/Adventures in Lestoria/assets/config/Monsters.txt b/Adventures in Lestoria/assets/config/Monsters.txt index de6b940b..b61b8a89 100644 --- a/Adventures in Lestoria/assets/config/Monsters.txt +++ b/Adventures in Lestoria/assets/config/Monsters.txt @@ -514,7 +514,8 @@ Monsters #Additional custom animations go down below. Start with ANIMATION[0] Order is: # File name, Frame Count, Frame Speed (s), Frame Cycling (Repeat,OneShot,PingPong,Reverse) # NOTE: ANIMATION[0] will always be row 5 of an animation sheet, all numbers that follow are each below each other. - # ANIMATION[0] = 4, 0.1, OneShot + # Scratch animation. + ANIMATION[0] = 1, 0.1, OneShot } Goblin (Bow) { diff --git a/Adventures in Lestoria/olcUTIL_Animate2D.h b/Adventures in Lestoria/olcUTIL_Animate2D.h index 60df9bb8..98aeb0ce 100644 --- a/Adventures in Lestoria/olcUTIL_Animate2D.h +++ b/Adventures in Lestoria/olcUTIL_Animate2D.h @@ -128,6 +128,25 @@ namespace olc::utils::Animate2D return m_vFrames[ConvertTimeToFrame(fTime)]; } + // Returns the current frame of animation as a frame index. + inline const size_t GetFrameIndex(const float fTime) const + { + return ConvertTimeToFrame(fTime); + } + + // Returns how long a cycle of a full animation takes in seconds. + inline const float GetTotalAnimationDuration()const{ + switch (m_nStyle) + { + case Style::Repeat: + case Style::OneShot: + return m_vFrames.size()*m_fFrameDuration; + case Style::PingPong: + case Style::Reverse: //These two require twice as much time (minus one frame) to complete a full animation cycle. + return m_vFrames.size()*m_fFrameDuration*2.f-m_fFrameDuration; + } + } + private: inline const size_t ConvertTimeToFrame(const float fTime) const @@ -171,15 +190,18 @@ namespace olc::utils::Animate2D public: Animation() = default; float mult = 1.f; + StatesEnum currentStateName; inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName, const float frameMult) { mult=frameMult; + currentStateName=sStateName; return ChangeState(state,sStateName); } // Change an animation state token to a new state inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName) const { + currentStateName=sStateName; size_t idx = m_mapStateIndices.at(sStateName); if (state.nIndex != idx) { @@ -204,6 +226,10 @@ namespace olc::utils::Animate2D return m_vSequences[state.nIndex].GetFrame(state.fTime); } + inline const size_t GetFrameIndex()const{ + return m_vSequences[state.nIndex].GetFrameIndex(state.fTime); + } + public: // Add a named Frame sequence as a state inline void AddState(const StatesEnum& sStateName, const FrameSequence& sequence)