@ -688,7 +688,7 @@ void Player::Update(float fElapsedTime){
float angleToCursor = atan2 ( extendedLine . y - GetPos ( ) . y , extendedLine . x - GetPos ( ) . x ) ;
attack_cooldown_timer = ARROW_ATTACK_COOLDOWN ;
BULLET_LIST . push_back ( std : : make_unique < Arrow > ( Arrow ( GetPos ( ) , extendedLine , vf2d { cos ( angleToCursor ) * " Ranger.Ability 1.ArrowSpd " _F , float ( sin ( angleToCursor ) * " Ranger.Ability 1.ArrowSpd " _F - PI / 8 * " Ranger.Ability 1.ArrowSpd " _F ) } + movementVelocity / 1.5f , 12 * " Ranger.Ability 1.ArrowRadius " _F / 100 , int ( GetAttack ( ) * " Ranger.Ability 1.DamageMult " _F ) , OnUpperLevel ( ) , true ) ) ) ;
SetAnimationBasedOnTargetingDirection ( angleToCursor ) ;
SetAnimationBasedOnTargetingDirection ( " SHOOT " , angleToCursor ) ;
rapidFireTimer = RAPID_FIRE_SHOOT_DELAY ;
} else {
SetState ( State : : NORMAL ) ;
@ -731,7 +731,7 @@ vf2d Player::GetVelocity(){
}
bool Player : : CanMove ( ) {
return knockUpTimer = = 0.f & & state ! = State : : ANIMATION_LOCK & & ( state ! = State : : CASTING | | ( castInfo . castTotalTime - castInfo . castTimer > 0.2f ) ) ;
return knockUpTimer = = 0.f & & state ! = State : : ANIMATION_LOCK & & state ! = State : : DEADLYDASH & & ( state ! = State : : CASTING | | ( castInfo . castTotalTime - castInfo . castTimer > 0.2f ) ) ;
}
bool Player : : CanAct ( ) {
@ -740,7 +740,7 @@ bool Player::CanAct(){
}
const bool Player : : CanAct ( const Ability & ability ) {
return knockUpTimer = = 0 & & ! ability . waitForRelease & & ( ability . canCancelCast | | state ! = State : : CASTING ) & & state ! = State : : ANIMATION_LOCK & &
return knockUpTimer = = 0 & & ! ability . waitForRelease & & ( ability . canCancelCast | | state ! = State : : CASTING ) & & state ! = State : : ANIMATION_LOCK & & state ! = State : : DEADLYDASH & &
( GameState : : STATE = = GameState : : states [ States : : GAME_RUN ]
| | GameState : : STATE = = GameState : : states [ States : : GAME_HUB ] & & ! ability . itemAbility ) ;
}
@ -1022,57 +1022,30 @@ void Player::SetVelocity(vf2d vel){
this - > vel = vel ;
}
void Player : : SetAnimationBasedOnTargetingDirection ( float targetDirection ) {
void Player : : SetAnimationBasedOnTarget ( const std : : string_view animation_name , const vf2d & target ) {
SetAnimationBasedOnTargetingDirection ( animation_name , util : : pointTo ( GetPos ( ) , target ) . polar ( ) . y ) ;
}
void Player : : SetAnimationBasedOnTargetingDirection ( const std : : string_view animation_name , float targetDirection ) {
auto FacingEast = [ & ] ( ) { return targetDirection < = PI / 4 & & targetDirection > - PI / 4 ; } ;
auto FacingWest = [ & ] ( ) { return targetDirection > = 3 * PI / 4 | | targetDirection < - 3 * PI / 4 ; } ;
auto FacingSouth = [ & ] ( ) { return targetDirection < = 3 * PI / 4 & & targetDirection > PI / 4 ; } ;
auto FacingNorth = [ & ] ( ) { return targetDirection > = - 3 * PI / 4 & & targetDirection < - PI / 4 ; } ;
//Assume facing North.
char facingChar { ' N ' } ;
auto Capitalize = [ ] ( const std : : string_view str ) {
std : : string newStr ;
newStr . resize ( str . length ( ) ) ;
for ( int i = 0 ; const char & c : str ) newStr [ i + + ] = toupper ( c ) ; \
return newStr ;
} ;
switch ( GetClass ( ) ) {
case Class : : WARRIOR : {
if ( FacingNorth ( ) ) {
UpdateAnimation ( " WARRIOR_SWINGSWORD_N " ) ;
} else
if ( FacingSouth ( ) ) {
UpdateAnimation ( " WARRIOR_SWINGSWORD_S " ) ;
} else
if ( FacingWest ( ) ) {
UpdateAnimation ( " WARRIOR_SWINGSWORD_W " ) ;
} else
if ( FacingEast ( ) ) {
UpdateAnimation ( " WARRIOR_SWINGSWORD_E " ) ;
}
} break ;
case Class : : RANGER :
case Class : : TRAPPER : {
if ( FacingNorth ( ) ) {
UpdateAnimation ( " RANGER_SHOOT_N " ) ;
} else
if ( FacingSouth ( ) ) {
UpdateAnimation ( " RANGER_SHOOT_S " ) ;
} else
if ( FacingWest ( ) ) {
UpdateAnimation ( " RANGER_SHOOT_W " ) ;
} else
if ( FacingEast ( ) ) {
UpdateAnimation ( " RANGER_SHOOT_E " ) ;
}
} break ;
case Class : : THIEF : {
if ( FacingNorth ( ) ) {
UpdateAnimation ( " THIEF_SWINGSWORD_N " ) ;
} else
if ( FacingSouth ( ) ) {
UpdateAnimation ( " THIEF_SWINGSWORD_S " ) ;
} else
if ( FacingWest ( ) ) {
UpdateAnimation ( " THIEF_SWINGSWORD_W " ) ;
} else
if ( FacingEast ( ) ) {
UpdateAnimation ( " THIEF_SWINGSWORD_E " ) ;
}
} break ;
}
if ( FacingSouth ( ) ) facingChar = ' S ' ;
if ( FacingEast ( ) ) facingChar = ' E ' ;
if ( FacingWest ( ) ) facingChar = ' W ' ;
UpdateAnimation ( std : : format ( " {}_{}_{} " , Capitalize ( GetClassName ( ) ) , animation_name , facingChar ) ) ;
}
void Player : : ApplyIframes ( float duration ) {