|
|
|
@ -28,7 +28,7 @@ BasicUnit2::BasicUnit2(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAG |
|
|
|
|
},pos,*IMAGES[VIRUS_IMG1],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void BasicUnit2::Attack(Unit&victim){ |
|
|
|
|
|
|
|
|
|
victim>>=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LeftShifter::LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) |
|
|
|
@ -41,7 +41,7 @@ LeftShifter::LeftShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IM |
|
|
|
|
},pos,*IMAGES[LEFT_SHIFTER],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void LeftShifter::Attack(Unit&victim){ |
|
|
|
|
|
|
|
|
|
victim<<=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RightShifter::RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) |
|
|
|
@ -54,7 +54,7 @@ RightShifter::RightShifter(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>& |
|
|
|
|
},pos,*IMAGES[RIGHT_SHIFTER],friendly,moveable){} |
|
|
|
|
|
|
|
|
|
void RightShifter::Attack(Unit&victim){ |
|
|
|
|
|
|
|
|
|
victim>>=1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BitRestorer::BitRestorer(vf2d pos,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,bool friendly,bool moveable) |
|
|
|
@ -266,8 +266,6 @@ void Unit::_Update(PixelGameEngine*pge){ |
|
|
|
|
auto ptrTarget=target.lock(); |
|
|
|
|
if(!InRange(ptrTarget)){ |
|
|
|
|
SetPos(GetPos()+(ptrTarget->GetPos()-pos).norm()*GetMoveSpd()*24*pge->GetElapsedTime()); |
|
|
|
|
} else { |
|
|
|
|
//TODO Attack here.
|
|
|
|
|
} |
|
|
|
|
} else
|
|
|
|
|
if(targetLoc!=CONSTANT::UNSELECTED){ |
|
|
|
@ -366,13 +364,19 @@ void Unit::SetTargetLocation(vf2d targetLoc){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Unit::InRange(std::shared_ptr<Unit>target){ |
|
|
|
|
float dist=geom2d::line(GetPos(),target->GetPos()).length(); |
|
|
|
|
return dist<24*(GetRange()+1); |
|
|
|
|
return InRange(target.get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Unit::InRange(Unit*target){ |
|
|
|
|
float range=12*(GetRange()+1); |
|
|
|
|
float totalRange=GetUnitSize().x/2+range; |
|
|
|
|
return geom2d::overlaps(geom2d::circle<float>{GetPos(),totalRange},geom2d::circle<float>{target->GetPos(),target->GetUnitSize().x/2}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Unit::InRange(vf2d pos){ |
|
|
|
|
float dist=geom2d::line(GetPos(),pos).length(); |
|
|
|
|
return dist<24*(GetRange()+1); |
|
|
|
|
float range=12*(GetRange()+1); |
|
|
|
|
float totalRange=GetUnitSize().x/2+range; |
|
|
|
|
return geom2d::overlaps(geom2d::circle<float>{GetPos(),totalRange},geom2d::circle<float>{pos,0.1}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Unit::SetPos(vf2d newPos){ |
|
|
|
@ -395,7 +399,7 @@ void Unit::AttemptAttack(Unit*unit){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(finalTarget!=nullptr){ |
|
|
|
|
if(InRange(finalTarget->GetPos())){ |
|
|
|
|
if(InRange(finalTarget)){ |
|
|
|
|
_Attack(finalTarget); //Call the parent function first, followed by the child.
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|