Add animation utilities for getting current animation frame index and total animation duration.

mac-build
sigonasr2 11 months ago
parent 6a5dfa8e42
commit c15fc769e1
  1. 7
      Adventures in Lestoria/Boar.cpp
  2. 4
      Adventures in Lestoria/Monster.cpp
  3. 1
      Adventures in Lestoria/Monster.h
  4. 1
      Adventures in Lestoria/MonsterAttribute.h
  5. 3
      Adventures in Lestoria/assets/config/Monsters.txt
  6. 26
      Adventures in Lestoria/olcUTIL_Animate2D.h

@ -46,6 +46,7 @@ If range to player<400 backpaddle with 50% move-spd. if getting hit while backpa
*/ */
INCLUDE_game INCLUDE_game
INCLUDE_ANIMATION_DATA
using A=Attribute; using A=Attribute;
void Monster::STRATEGY::BOAR(Monster&m,float fElapsedTime,std::string strategy){ void Monster::STRATEGY::BOAR(Monster&m,float fElapsedTime,std::string strategy){
@ -67,7 +68,11 @@ void Monster::STRATEGY::BOAR(Monster&m,float fElapsedTime,std::string strategy){
m.AddBuff(BuffType::SLOWDOWN,INFINITE,(100-ConfigInt("Backpedal Movespeed"))/100.f); m.AddBuff(BuffType::SLOWDOWN,INFINITE,(100-ConfigInt("Backpedal Movespeed"))/100.f);
RUN_AWAY(m,fElapsedTime,"Run Away"); RUN_AWAY(m,fElapsedTime,"Run Away");
m.UpdateFacingDirection(game->GetPlayer()->GetPos()); 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; }break;
case PhaseName::SCRATCH:{ case PhaseName::SCRATCH:{
m.RemoveBuff(BuffType::SLOWDOWN); m.RemoveBuff(BuffType::SLOWDOWN);

@ -846,3 +846,7 @@ const bool Monster::IsNPC()const{
const bool MonsterData::IsNPC()const{ const bool MonsterData::IsNPC()const{
return isNPC; return isNPC;
} }
const Animate2D::FrameSequence&Monster::GetCurrentAnimation()const{
return ANIMATION_DATA[animation.currentStateName];
}

@ -109,6 +109,7 @@ public:
void PerformNPCLeftAnimation(); void PerformNPCLeftAnimation();
void PerformNPCRightAnimation(); void PerformNPCRightAnimation();
void PerformOtherAnimation(const uint8_t otherInd); void PerformOtherAnimation(const uint8_t otherInd);
const Animate2D::FrameSequence&GetCurrentAnimation()const;
bool OnUpperLevel(); bool OnUpperLevel();
void Moved(); void Moved();
//Returns false if a path could not be found. //Returns false if a path could not be found.

@ -107,5 +107,4 @@ enum class Attribute{
LAST_JUMP_TIMER, LAST_JUMP_TIMER,
INITIALIZED, INITIALIZED,
JUMP_MOVE_TO_TARGET_TIMER, JUMP_MOVE_TO_TARGET_TIMER,
}; };

@ -514,7 +514,8 @@ Monsters
#Additional custom animations go down below. Start with ANIMATION[0] Order is: #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) # 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. # 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) Goblin (Bow)
{ {

@ -128,6 +128,25 @@ namespace olc::utils::Animate2D
return m_vFrames[ConvertTimeToFrame(fTime)]; 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: private:
inline const size_t ConvertTimeToFrame(const float fTime) const inline const size_t ConvertTimeToFrame(const float fTime) const
@ -171,15 +190,18 @@ namespace olc::utils::Animate2D
public: public:
Animation() = default; Animation() = default;
float mult = 1.f; float mult = 1.f;
StatesEnum currentStateName;
inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName, const float frameMult) inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName, const float frameMult)
{ {
mult=frameMult; mult=frameMult;
currentStateName=sStateName;
return ChangeState(state,sStateName); return ChangeState(state,sStateName);
} }
// Change an animation state token to a new state // Change an animation state token to a new state
inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName) const inline bool ChangeState(AnimationState& state, const StatesEnum& sStateName) const
{ {
currentStateName=sStateName;
size_t idx = m_mapStateIndices.at(sStateName); size_t idx = m_mapStateIndices.at(sStateName);
if (state.nIndex != idx) if (state.nIndex != idx)
{ {
@ -204,6 +226,10 @@ namespace olc::utils::Animate2D
return m_vSequences[state.nIndex].GetFrame(state.fTime); return m_vSequences[state.nIndex].GetFrame(state.fTime);
} }
inline const size_t GetFrameIndex()const{
return m_vSequences[state.nIndex].GetFrameIndex(state.fTime);
}
public: public:
// Add a named Frame sequence as a state // Add a named Frame sequence as a state
inline void AddState(const StatesEnum& sStateName, const FrameSequence& sequence) inline void AddState(const StatesEnum& sStateName, const FrameSequence& sequence)

Loading…
Cancel
Save