Add animation utilities for getting current animation frame index and total animation duration.
This commit is contained in:
parent
6a5dfa8e42
commit
c15fc769e1
@ -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,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);
|
||||
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);
|
||||
|
@ -846,3 +846,7 @@ const bool Monster::IsNPC()const{
|
||||
const bool MonsterData::IsNPC()const{
|
||||
return isNPC;
|
||||
}
|
||||
|
||||
const Animate2D::FrameSequence&Monster::GetCurrentAnimation()const{
|
||||
return ANIMATION_DATA[animation.currentStateName];
|
||||
}
|
@ -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.
|
||||
|
@ -107,5 +107,4 @@ enum class Attribute{
|
||||
LAST_JUMP_TIMER,
|
||||
INITIALIZED,
|
||||
JUMP_MOVE_TO_TARGET_TIMER,
|
||||
|
||||
};
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user