public void Attack() { #region Move to shooting position if (ship.BoundingX + ship.BoundingWidth < Game1.ScreenSize.X - 20 && targetYDistance > 0 && ship.PositionX < target.BoundingX) { ship.Move(new Vector2(1, ship.DirectionY)); } else if (ship.BoundingX > 20 && targetYDistance > 0 && ship.PositionX > target.BoundingX + target.BoundingWidth) { ship.Move(new Vector2(-1, ship.DirectionY)); } else { ship.Stop("x"); } if (ship.BoundingY > 20 && targetYDistance > shotRange && ship.BoundingY > 10) { ship.Move(new Vector2(ship.DirectionX, -1)); } else if (ship.BoundingY + ship.BoundingHeight < (Game1.ScreenSize.Y - 600) / 2 + 600 && targetYDistance > -20 && targetYDistance < 50 && ship.BoundingY + ship.BoundingHeight < Game1.ScreenSize.Y - 10) { ship.Move(new Vector2(ship.DirectionX, 1)); } else { ship.Stop("y"); } #endregion #region Shoot if (ship.PositionX < target.BoundingX + target.BoundingWidth && ship.PositionX > target.BoundingX && targetYDistance < shotRange) { ship.Shoot(); } #endregion }
//Logic public virtual void Action() { switch (aIAction) { case AIAction.Idle: Ship.Stop(); break; case AIAction.Attack: ai.Attack(); break; case AIAction.Avoid: ai.Avoid(); break; case AIAction.Formation: Ship.MoveToArea(ai.FormationArea); break; } }