diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 02b680a8..702c7ce7 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -124,6 +124,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ } else { player.SetX(WORLD_SIZE.x*24-12); } + player.SetFacingDirection(RIGHT); player.UpdateAnimation(AnimationState::WALK_E); setIdleAnimation=false; } @@ -134,6 +135,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ player.SetX(12); } if(setIdleAnimation){ + player.SetFacingDirection(LEFT); player.UpdateAnimation(AnimationState::WALK_W); } setIdleAnimation=false; @@ -145,6 +147,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ player.SetY(12); } if(setIdleAnimation){ + player.SetFacingDirection(UP); player.UpdateAnimation(AnimationState::WALK_N); } setIdleAnimation=false; @@ -156,6 +159,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ player.SetY(WORLD_SIZE.y*24-12); } if(setIdleAnimation){ + player.SetFacingDirection(DOWN); player.UpdateAnimation(AnimationState::WALK_S); } setIdleAnimation=false; diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index a7106b84..17e2c265 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -88,26 +88,26 @@ void Player::Update(float fElapsedTime){ attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime); switch(state){ case SPIN:{ - switch(lastReleasedMovementKey){ + switch(facingDirection){ case UP:{ if(lastAnimationFlip==0){ lastAnimationFlip=0.03; - lastReleasedMovementKey=DOWN; + facingDirection=DOWN; animation.ChangeState(internal_animState,AnimationState::WALK_S); } }break; case DOWN:{ if(lastAnimationFlip==0){ lastAnimationFlip=0.03; - lastReleasedMovementKey=UP; + facingDirection=UP; animation.ChangeState(internal_animState,AnimationState::WALK_N); } }break; } - if(lastReleasedMovementKey==DOWN||lastReleasedMovementKey==RIGHT){ - spin_angle-=spin_spd*fElapsedTime; - } else { + if(facingDirection==RIGHT){ spin_angle+=spin_spd*fElapsedTime; + } else { + spin_angle-=spin_spd*fElapsedTime; } if(spin_attack_timer>0){ z=50*sin(3.3*(GROUND_SLAM_SPIN_TIME-spin_attack_timer)/GROUND_SLAM_SPIN_TIME); @@ -117,10 +117,14 @@ void Player::Update(float fElapsedTime){ spin_angle=0; z=0; } + if(lastAnimationFlip>0){ + lastAnimationFlip=std::max(0.f,lastAnimationFlip-fElapsedTime); + } }break; default:{ //Update animations normally. } + [[fallthrough]]; } animation.UpdateState(internal_animState,fElapsedTime); if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){ @@ -163,6 +167,14 @@ Key Player::GetLastReleasedMovementKey(){ return lastReleasedMovementKey; } +void Player::SetFacingDirection(Key direction){ + facingDirection=direction; +} + +Key Player::GetFacingDirection(){ + return facingDirection; +} + void Player::Moved(){ for(MonsterSpawner&spawner:SPAWNER_LIST){ if(!spawner.SpawnTriggered()&&geom2d::overlaps(geom2d::circle(pos-vf2d{size*12,size*12},size*12),geom2d::circle(spawner.GetPos(),spawner.GetRange()))){ diff --git a/Crawler/Player.h b/Crawler/Player.h index 575d4472..3dee7b4c 100644 --- a/Crawler/Player.h +++ b/Crawler/Player.h @@ -23,6 +23,7 @@ private: Animate2D::Animationanimation; Animate2D::AnimationState internal_animState; Key lastReleasedMovementKey; + Key facingDirection; public: Player(); Player(vf2d pos); @@ -43,6 +44,8 @@ public: float GetAttackRangeMult(); float GetSpinAngle(); State GetState(); + void SetFacingDirection(Key direction); + Key GetFacingDirection(); void Hurt(int damage);