Auto attacking now based on click position. Damage numbers will stop when they reach a certain height. Monsters not counted in range if dead.

This commit is contained in:
2023-06-15 04:53:57 -05:00
parent 3aebde6287
commit 7c542740cc
6 changed files with 45 additions and 13 deletions
+9 -6
View File
@@ -133,21 +133,24 @@ void Player::Update(float fElapsedTime){
groundSlamCooldown=std::max(0.f,groundSlamCooldown-fElapsedTime);
if(attack_cooldown_timer==0&&game->GetMouse(0).bHeld){
bool attack=false;
Monster*closest=nullptr;
float closest_dist=999999;
for(Monster&m:MONSTER_LIST){
if(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))){
if(m.Hurt(atk)){
attack=true;
break;
}
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(attack){
if(closest!=nullptr&&closest->Hurt(atk)){
attack_cooldown_timer=ATTACK_COOLDOWN;
}
}
}
void Player::Hurt(int damage){
if(hp<=0) return;
hp=std::max(0,hp-damage);
DAMAGENUMBER_LIST.push_back(DamageNumber(pos,damage));
}