diff --git a/Adventures in Lestoria/Monster.cpp b/Adventures in Lestoria/Monster.cpp index 1bd4031d..51596ef9 100644 --- a/Adventures in Lestoria/Monster.cpp +++ b/Adventures in Lestoria/Monster.cpp @@ -265,6 +265,7 @@ bool Monster::Update(float fElapsedTime){ monsterHurtSoundCooldown=std::max(0.f,monsterHurtSoundCooldown-fElapsedTime); lastHitPlayer=std::max(0.f,lastHitPlayer-fElapsedTime); lastPathfindingCooldown=std::max(0.f,lastPathfindingCooldown-fElapsedTime); + lastFacingDirectionChange+=fElapsedTime; if(size!=targetSize){ if(size>targetSize){ @@ -353,9 +354,15 @@ Direction Monster::GetFacingDirection()const{ } void Monster::UpdateFacingDirection(vf2d facingTargetPoint){ - if(HasFourWaySprites()){ - vf2d diff=GetPos()-facingTargetPoint; + float facingAngle=util::angleTo(GetPos(),facingTargetPoint); + vf2d diff=GetPos()-facingTargetPoint; + + if(abs(facingAngle-prevFacingDirectionAngle)<(7*PI)/16.f||lastFacingDirectionChange<0.25f)return; //We don't want to change facing angle until a more drastic angle of change has occurred. About 1/4 circle should be acceptable. + + prevFacingDirectionAngle=facingAngle; + lastFacingDirectionChange=0.f; + if(HasFourWaySprites()){ if(abs(diff.x)>abs(diff.y)){ if(facingTargetPoint.x>GetPos().x){ facingDirection=Direction::EAST; @@ -373,10 +380,9 @@ void Monster::UpdateFacingDirection(vf2d facingTargetPoint){ } animation.ModifyDisplaySprite(internal_animState,std::format("{}_{}",animation.currentStateName.substr(0,animation.currentStateName.length()-2),int(facingDirection))); }else{ - if(facingTargetPoint.x>GetPos().x){ + if(diff.x>0){ facingDirection=Direction::EAST; - } - if(facingTargetPoint.xSpawnDrops(); + float prevFacingDirectionAngle=0.f; //Keeps track of the angle of the previous target to ensure four-way sprite facing changes don't happen too early or spastically. + float lastFacingDirectionChange=0.f; //How much time has passed since the last facing direction change. Used to ensure another facing direction change doesn't happen too quickly. Probably allowing one every quarter second is good enough. private: struct STRATEGY{ diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index cbe520c8..9f88c174 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 9174 +#define VERSION_BUILD 9176 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index 66f55592..03bdd512 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ