|
|
|
@ -67,11 +67,19 @@ int Player::GetMaxHealth(){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int Player::GetAttack(){ |
|
|
|
|
return atk; |
|
|
|
|
float mod_atk=atk; |
|
|
|
|
for(Buff&b:GetBuffs(BuffType::ATTACK_UP)){ |
|
|
|
|
mod_atk+=atk*b.intensity; |
|
|
|
|
} |
|
|
|
|
return int(mod_atk); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float Player::GetMoveSpdMult(){ |
|
|
|
|
return moveSpd; |
|
|
|
|
float mod_moveSpd=moveSpd; |
|
|
|
|
for(Buff&b:GetBuffs(BuffType::SLOWDOWN)){ |
|
|
|
|
mod_moveSpd-=moveSpd*b.intensity; |
|
|
|
|
} |
|
|
|
|
return mod_moveSpd; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
float Player::GetSizeMult(){ |
|
|
|
@ -93,6 +101,14 @@ State Player::GetState(){ |
|
|
|
|
void Player::Update(float fElapsedTime){ |
|
|
|
|
attack_cooldown_timer=std::max(0.f,attack_cooldown_timer-fElapsedTime); |
|
|
|
|
iframe_time=std::max(0.f,iframe_time-fElapsedTime); |
|
|
|
|
for(std::vector<Buff>::iterator it=buffList.begin();it!=buffList.end();++it){ |
|
|
|
|
Buff&b=*it; |
|
|
|
|
b.duration-=fElapsedTime; |
|
|
|
|
if(b.duration<=0){ |
|
|
|
|
it=buffList.erase(it); |
|
|
|
|
if(it==buffList.end())break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
switch(state){ |
|
|
|
|
case SPIN:{ |
|
|
|
|
switch(facingDirection){ |
|
|
|
@ -123,7 +139,7 @@ void Player::Update(float fElapsedTime){ |
|
|
|
|
state=NORMAL; |
|
|
|
|
spin_angle=0; |
|
|
|
|
z=0; |
|
|
|
|
game->HurtEnemies(pos,3*12,atk*2.5); |
|
|
|
|
game->HurtEnemies(pos,3*12,GetAttack()*2.5); |
|
|
|
|
game->AddEffect(Effect{GetPos(),0.5,AnimationState::GROUND_SLAM_ATTACK_FRONT,1.33f,0.6f},Effect{GetPos(),0.5,AnimationState::GROUND_SLAM_ATTACK_BACK,1.33f,0.6f}); |
|
|
|
|
} |
|
|
|
|
if(lastAnimationFlip>0){ |
|
|
|
@ -138,7 +154,6 @@ void Player::Update(float fElapsedTime){ |
|
|
|
|
}break; |
|
|
|
|
default:{ |
|
|
|
|
//Update animations normally.
|
|
|
|
|
moveSpd=1.0; |
|
|
|
|
animation.UpdateState(internal_animState,fElapsedTime); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -179,35 +194,62 @@ void Player::Update(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){ |
|
|
|
|
switch (cl) { |
|
|
|
|
case WARRIOR: { |
|
|
|
|
bool attack=false; |
|
|
|
|
Monster*closest=nullptr; |
|
|
|
|
float closest_dist=999999; |
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
if(m.IsAlive() |
|
|
|
|
&&geom2d::overlaps(geom2d::circle<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12)) |
|
|
|
|
&&geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length()<closest_dist){ |
|
|
|
|
closest_dist=geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length(); |
|
|
|
|
closest=&m; |
|
|
|
|
case WARRIOR:{ |
|
|
|
|
if(state!=State::SPIN){ |
|
|
|
|
bool attack=false; |
|
|
|
|
Monster*closest=nullptr; |
|
|
|
|
float closest_dist=999999; |
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
if(m.IsAlive() |
|
|
|
|
&&geom2d::overlaps(geom2d::circle<float>(pos-vf2d{size*12,size*12},attack_range*size*12),geom2d::circle<float>(m.GetPos()-vf2d{m.GetSizeMult()*12,m.GetSizeMult()*12},m.GetSizeMult()*12)) |
|
|
|
|
&&geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length()<closest_dist){ |
|
|
|
|
closest_dist=geom2d::line<float>(game->GetWorldMousePos(),m.GetPos()).length(); |
|
|
|
|
closest=&m; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(closest!=nullptr&&closest->Hurt(GetAttack())){ |
|
|
|
|
attack_cooldown_timer=ATTACK_COOLDOWN; |
|
|
|
|
swordSwingTimer=0.2; |
|
|
|
|
SetState(State::SWING_SWORD); |
|
|
|
|
switch(facingDirection){ |
|
|
|
|
case DOWN:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_S); |
|
|
|
|
}break; |
|
|
|
|
case RIGHT:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_E); |
|
|
|
|
}break; |
|
|
|
|
case LEFT:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_W); |
|
|
|
|
}break; |
|
|
|
|
case UP:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_N); |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(closest!=nullptr&&closest->Hurt(atk)){ |
|
|
|
|
attack_cooldown_timer=ATTACK_COOLDOWN; |
|
|
|
|
swordSwingTimer=0.2; |
|
|
|
|
SetState(State::SWING_SWORD); |
|
|
|
|
switch(facingDirection){ |
|
|
|
|
case DOWN:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_S); |
|
|
|
|
}break; |
|
|
|
|
case RIGHT:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_E); |
|
|
|
|
}break; |
|
|
|
|
case LEFT:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_W); |
|
|
|
|
}break; |
|
|
|
|
case UP:{ |
|
|
|
|
UpdateAnimation(AnimationState::SWINGSWORD_N); |
|
|
|
|
}break; |
|
|
|
|
}break; |
|
|
|
|
case THIEF: { |
|
|
|
|
}break; |
|
|
|
|
case RANGER: { |
|
|
|
|
}break; |
|
|
|
|
case BARD: { |
|
|
|
|
}break; |
|
|
|
|
case WIZARD: { |
|
|
|
|
}break; |
|
|
|
|
case WITCH: { |
|
|
|
|
}break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(ability1.cooldown==0&&game->GetKey(SHIFT).bHeld){ |
|
|
|
|
switch (cl) { |
|
|
|
|
case WARRIOR: { |
|
|
|
|
game->AddEffect(Effect(pos,0.1,AnimationState::BATTLECRY_EFFECT,1,0.3)); |
|
|
|
|
ability1.cooldown=ability1.COOLDOWN_TIME; |
|
|
|
|
AddBuff(BuffType::ATTACK_UP,10,0.1); |
|
|
|
|
AddBuff(BuffType::DAMAGE_REDUCTION,10,0.1); |
|
|
|
|
for(Monster&m:MONSTER_LIST){ |
|
|
|
|
if(geom2d::overlaps(geom2d::circle<float>(pos,12*3.5),geom2d::circle<float>(m.GetPos(),m.GetSizeMult()*12))){ |
|
|
|
|
m.AddBuff(BuffType::SLOWDOWN,5,0.3); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
@ -229,7 +271,7 @@ void Player::Update(float fElapsedTime){ |
|
|
|
|
if(GetState()==State::NORMAL){ |
|
|
|
|
rightClickAbility.cooldown=rightClickAbility.COOLDOWN_TIME; |
|
|
|
|
SetState(State::BLOCK); |
|
|
|
|
moveSpd=0.7; |
|
|
|
|
AddBuff(BuffType::SLOWDOWN,3,0.3); |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case THIEF: { |
|
|
|
@ -269,8 +311,12 @@ bool Player::HasIframes(){ |
|
|
|
|
bool Player::Hurt(int damage){ |
|
|
|
|
if(hp<=0||iframe_time!=0) return false; |
|
|
|
|
if(state==State::BLOCK)damage=0; |
|
|
|
|
hp=std::max(0,hp-damage); |
|
|
|
|
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage)); |
|
|
|
|
float mod_dmg=damage; |
|
|
|
|
for(Buff&b:GetBuffs(BuffType::DAMAGE_REDUCTION)){ |
|
|
|
|
mod_dmg-=damage*b.intensity; |
|
|
|
|
} |
|
|
|
|
hp=std::max(0,hp-int(mod_dmg)); |
|
|
|
|
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,int(mod_dmg))); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -346,3 +392,13 @@ void Player::UpdateIdleAnimation(Key direction){ |
|
|
|
|
} |
|
|
|
|
UpdateAnimation(anim); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Player::AddBuff(BuffType type,float duration,float intensity){ |
|
|
|
|
buffList.push_back(Buff{type,duration,intensity}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::vector<Buff>Player::GetBuffs(BuffType buff){ |
|
|
|
|
std::vector<Buff>filteredBuffs; |
|
|
|
|
std::copy_if(buffList.begin(),buffList.end(),std::back_inserter(filteredBuffs),[buff](Buff&b){return b.type==buff;}); |
|
|
|
|
return filteredBuffs; |
|
|
|
|
} |