Prevent monster facing directions from changing so rapidly and only allow directional changes when enough directional change has been reached for less choppy facing animations. Release Build 9176.

pull/57/head
sigonasr2 7 months ago
parent 253bbc610e
commit 365d66098e
  1. 16
      Adventures in Lestoria/Monster.cpp
  2. 2
      Adventures in Lestoria/Monster.h
  3. 2
      Adventures in Lestoria/Version.h
  4. BIN
      x64/Release/Adventures in Lestoria.exe

@ -265,6 +265,7 @@ bool Monster::Update(float fElapsedTime){
monsterHurtSoundCooldown=std::max(0.f,monsterHurtSoundCooldown-fElapsedTime); monsterHurtSoundCooldown=std::max(0.f,monsterHurtSoundCooldown-fElapsedTime);
lastHitPlayer=std::max(0.f,lastHitPlayer-fElapsedTime); lastHitPlayer=std::max(0.f,lastHitPlayer-fElapsedTime);
lastPathfindingCooldown=std::max(0.f,lastPathfindingCooldown-fElapsedTime); lastPathfindingCooldown=std::max(0.f,lastPathfindingCooldown-fElapsedTime);
lastFacingDirectionChange+=fElapsedTime;
if(size!=targetSize){ if(size!=targetSize){
if(size>targetSize){ if(size>targetSize){
@ -353,9 +354,15 @@ Direction Monster::GetFacingDirection()const{
} }
void Monster::UpdateFacingDirection(vf2d facingTargetPoint){ void Monster::UpdateFacingDirection(vf2d facingTargetPoint){
if(HasFourWaySprites()){ float facingAngle=util::angleTo(GetPos(),facingTargetPoint);
vf2d diff=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(abs(diff.x)>abs(diff.y)){
if(facingTargetPoint.x>GetPos().x){ if(facingTargetPoint.x>GetPos().x){
facingDirection=Direction::EAST; 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))); animation.ModifyDisplaySprite(internal_animState,std::format("{}_{}",animation.currentStateName.substr(0,animation.currentStateName.length()-2),int(facingDirection)));
}else{ }else{
if(facingTargetPoint.x>GetPos().x){ if(diff.x>0){
facingDirection=Direction::EAST; facingDirection=Direction::EAST;
} }else{
if(facingTargetPoint.x<GetPos().x){
facingDirection=Direction::WEST; facingDirection=Direction::WEST;
} }
} }

@ -211,6 +211,8 @@ private:
float knockUpZAmt=0.f; float knockUpZAmt=0.f;
//Spawns the drops a monster would drop as if they were defeated. Returns what items were dropped and their amounts. //Spawns the drops a monster would drop as if they were defeated. Returns what items were dropped and their amounts.
std::map<ItemInfo*,uint16_t>SpawnDrops(); std::map<ItemInfo*,uint16_t>SpawnDrops();
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: private:
struct STRATEGY{ struct STRATEGY{

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 9174 #define VERSION_BUILD 9176
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save