|
|
@ -19,7 +19,7 @@ bool VirusAttack::OnUserCreate(){ |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true)); |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true)); |
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
if(rand()%2==0){ |
|
|
|
if(rand()%2==0){ |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false)); |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,true)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false)); |
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false)); |
|
|
|
} |
|
|
|
} |
|
|
@ -58,9 +58,7 @@ void VirusAttack::DrawSelectionRectangle(){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
void VirusAttack::HandleRightClickMove(){ |
|
|
|
HandleDraggingSelection(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (GetMouse(1).bPressed){ |
|
|
|
if (GetMouse(1).bPressed){ |
|
|
|
bool selectedTarget=false; |
|
|
|
bool selectedTarget=false; |
|
|
|
for(auto&u:units){ |
|
|
|
for(auto&u:units){ |
|
|
@ -85,10 +83,10 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
void VirusAttack::CollisionChecking(std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2){ |
|
|
|
for(auto&u2:units){ |
|
|
|
if(u!=u2&&geom2d::overlaps(geom2d::circle<float>(u->GetPos(),u->GetUnitSize().x/2),geom2d::circle<float>(u2->GetPos(),u2->GetUnitSize().x/2))){ |
|
|
|
if(&u!=&u2&&geom2d::overlaps(geom2d::circle<float>(u->GetPos(),u->GetUnitSize().x/2),geom2d::circle<float>(u2->GetPos(),u2->GetUnitSize().x/2))){ |
|
|
|
|
|
|
|
geom2d::line<float>collisionLine(u->GetPos(),u2->GetPos()); |
|
|
|
geom2d::line<float>collisionLine(u->GetPos(),u2->GetPos()); |
|
|
|
float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; |
|
|
|
float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; |
|
|
|
float dist=maxDist-collisionLine.length(); |
|
|
|
float dist=maxDist-collisionLine.length(); |
|
|
@ -97,6 +95,29 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
u2->SetPos(u2->GetPos()+dir*dist/2); |
|
|
|
u2->SetPos(u2->GetPos()+dir*dist/2); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std::shared_ptr<Unit>u,std::shared_ptr<Unit>u2){ |
|
|
|
|
|
|
|
if(u->IsFriendly()!=u2->IsFriendly()){ |
|
|
|
|
|
|
|
geom2d::line<float>unitLine(u->GetPos(),u2->GetPos()); |
|
|
|
|
|
|
|
if(unitLine.length()<closestDist){ |
|
|
|
|
|
|
|
closestUnit=u2.get(); |
|
|
|
|
|
|
|
closestDist=unitLine.length(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
|
|
|
HandleDraggingSelection(); |
|
|
|
|
|
|
|
HandleRightClickMove(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
|
|
|
|
Unit*closestUnit=nullptr; |
|
|
|
|
|
|
|
float closestDist=999999; |
|
|
|
|
|
|
|
for(auto&u2:units){ |
|
|
|
|
|
|
|
IdentifyClosestTarget(closestUnit,closestDist,u,u2); |
|
|
|
|
|
|
|
CollisionChecking(u,u2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
u->AttemptAttack(closestUnit); |
|
|
|
u->Update(fElapsedTime); |
|
|
|
u->Update(fElapsedTime); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|