|
|
|
@ -29,7 +29,7 @@ bool VirusAttack::OnUserCreate(){ |
|
|
|
|
|
|
|
|
|
void VirusAttack::HandleDraggingSelection(){ |
|
|
|
|
if(GetMouse(0).bPressed){ |
|
|
|
|
for(std::unique_ptr<Unit>&u:units){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
u->Deselect(); |
|
|
|
|
} |
|
|
|
|
if(startingDragPos==CONSTANT::UNSELECTED){ |
|
|
|
@ -40,10 +40,10 @@ void VirusAttack::HandleDraggingSelection(){ |
|
|
|
|
vf2d endDragPos=GetMousePos(); |
|
|
|
|
if(endDragPos.x<startingDragPos.x){std::swap(startingDragPos.x,endDragPos.x);} |
|
|
|
|
if(endDragPos.y<startingDragPos.y){std::swap(startingDragPos.y,endDragPos.y);} |
|
|
|
|
utils::geom2d::rect<float> selectionRegion(startingDragPos,endDragPos-startingDragPos); |
|
|
|
|
for(std::unique_ptr<Unit>&u:units){ |
|
|
|
|
geom2d::rect<float> selectionRegion(startingDragPos,endDragPos-startingDragPos); |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
if(u->IsFriendly()){ |
|
|
|
|
if(utils::geom2d::overlaps(selectionRegion,u->GetPos())){ |
|
|
|
|
if(geom2d::overlaps(selectionRegion,u->GetPos())){ |
|
|
|
|
u->Select(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -61,11 +61,46 @@ void VirusAttack::DrawSelectionRectangle(){ |
|
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
HandleDraggingSelection(); |
|
|
|
|
|
|
|
|
|
for(std::unique_ptr<Unit>&u:units){ |
|
|
|
|
if (GetMouse(1).bPressed){ |
|
|
|
|
bool selectedTarget=false; |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
if(!u->IsFriendly()){ |
|
|
|
|
geom2d::rect<float> unitRegion(u->GetPos()-u->GetUnitSize()/2,u->GetUnitSize()); |
|
|
|
|
if(geom2d::overlaps(unitRegion,GetMousePos())){ |
|
|
|
|
for(auto&u2:units){ |
|
|
|
|
if(u2->IsFriendly()&&u2->IsSelected()){ |
|
|
|
|
u2->SetTargetUnit(u); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
selectedTarget=true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(!selectedTarget){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
if(u->IsFriendly()&&u->IsSelected()){ |
|
|
|
|
u->SetTargetLocation(GetMousePos()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
|
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))){ |
|
|
|
|
geom2d::line<float>collisionLine(u->GetPos(),u2->GetPos()); |
|
|
|
|
float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; |
|
|
|
|
float dist=maxDist-collisionLine.length(); |
|
|
|
|
vf2d dir=collisionLine.vector().norm(); |
|
|
|
|
u->SetPos(u->GetPos()-dir*dist/2); |
|
|
|
|
u2->SetPos(u2->GetPos()+dir*dist/2); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
u->Update(fElapsedTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(std::unique_ptr<Unit>&u:units){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
u->Draw(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|