45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
namespace AirBomber.MovementStrategy
|
|||
|
{
|
|||
|
public class MoveToCenterStrategy : AbstractStrategy
|
|||
|
{
|
|||
|
protected override bool IsTargetDestination()
|
|||
|
{
|
|||
|
ObjectParameters? ObjParams = ObjectParameters;
|
|||
|
if (ObjParams is null)
|
|||
|
return false;
|
|||
|
|
|||
|
float FieldMiddleHorizontal = FieldWidth / 2;
|
|||
|
float FieldMiddleVertical = FieldHeight / 2;
|
|||
|
|
|||
|
return
|
|||
|
Math.Abs(ObjParams.ObjectMiddleHorizontal - FieldMiddleHorizontal) < GetStep() &&
|
|||
|
Math.Abs(ObjParams.ObjectMiddleVertical - FieldMiddleVertical) < GetStep();
|
|||
|
}
|
|||
|
|
|||
|
protected override void MoveToTarget()
|
|||
|
{
|
|||
|
ObjectParameters? ObjParams = ObjectParameters;
|
|||
|
if (ObjParams is null)
|
|||
|
return;
|
|||
|
|
|||
|
float diffX = ObjParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
|||
|
if (Math.Abs(diffX) > GetStep())
|
|||
|
{
|
|||
|
if (diffX > 0)
|
|||
|
MoveLeft();
|
|||
|
else
|
|||
|
MoveRight();
|
|||
|
}
|
|||
|
|
|||
|
float diffY = ObjParams.ObjectMiddleVertical - FieldHeight / 2;
|
|||
|
if (Math.Abs(diffY) > GetStep())
|
|||
|
{
|
|||
|
if (diffY > 0)
|
|||
|
MoveUp();
|
|||
|
else
|
|||
|
MoveDown();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|