public static void DrawCelestialObjectDirection(ICelestialObject celestialObject, PointF location, Graphics graphics, ScreenParameters screenParameters) { var screenCoordinates = UI.ToScreenCoordinates(screenParameters, new PointF(location.X, location.Y)); if ((CelestialObjectTypes)celestialObject.Classification == CelestialObjectTypes.Explosion) { return; } var move = SpaceMapTools.Move(screenCoordinates, 8, 6, celestialObject.Direction); SpaceMapGraphics.DrawArrow(graphics, move, Color.DimGray); }
public static void DrawArrow(Graphics graphics, SpaceMapVector line, Color color, int arrowSize = 4) { // Base arrow line graphics.DrawLine(new Pen(color), line.PointFrom.X, line.PointFrom.Y, line.PointTo.X, line.PointTo.Y); // Arrow left line var leftArrowLine = SpaceMapTools.Move(line.PointTo.ToVector2(), arrowSize, line.Direction + 150); graphics.DrawLine(new Pen(color), leftArrowLine.PointFrom.X, leftArrowLine.PointFrom.Y, leftArrowLine.PointTo.X, leftArrowLine.PointTo.Y); // Arrow right line var rightArrowLine = SpaceMapTools.Move(line.PointTo.ToVector2(), arrowSize, line.Direction - 150); graphics.DrawLine(new Pen(color), rightArrowLine.PointFrom.X, rightArrowLine.PointFrom.Y, rightArrowLine.PointTo.X, rightArrowLine.PointTo.Y); }
private static void DrawCurveTrajectory(Graphics graphics, List <SpaceMapObjectLocation> results, Color color, ScreenParameters screenParameters, bool isDrawArrow = false) { var points = new List <PointF>(); foreach (var position in results) { var screenCoordinates = UI.ToScreenCoordinates(screenParameters, new PointF(position.Coordinates.X, position.Coordinates.Y)); points.Add(new PointF(screenCoordinates.X, screenCoordinates.Y)); } var lastPoint = results[results.Count - 1]; var pointInSpaceCoordinates = UI.ToScreenCoordinates(screenParameters, new PointF(lastPoint.Coordinates.X, lastPoint.Coordinates.Y)); var step = SpaceMapTools.Move(pointInSpaceCoordinates, 4000, 0, lastPoint.Direction); if (points.Count > 2) { graphics.DrawCurve(new Pen(color), points.ToArray()); } graphics.DrawLine(new Pen(color), step.PointFrom, step.PointTo); var move = SpaceMapTools.Move(pointInSpaceCoordinates, 0, 0, lastPoint.Direction); SpaceMapGraphics.DrawArrow(graphics, move, color, 12); #region Show linear movement //foreach (var position in results) //{ // var screenCoordinates = UI.ToScreenCoordinates(_screenParameters, new PointF(position.Coordinates.X, position.Coordinates.Y)); // if (position.Status == MovementType.Linear) // { // graphics.DrawEllipse(new Pen(Color.Brown, 1), screenCoordinates.X, screenCoordinates.Y, 2, 2 ); // } //} #endregion }
public static void DrawConnectors(Graphics graphics, GameSession gameSession, IEnumerable <ICelestialObject> connectors, SortedDictionary <int, GranularObjectInformation> granularTurnInformation, int turnStep, ScreenParameters screenParameters) { if (connectors == null || !connectors.Any()) { return; } var playerSpaceship = gameSession.GetPlayerSpaceShip(); var connectorPen = new Pen(Color.DimGray); var objectsInScreenArea = connectors.Where(o => screenParameters.PointInVisibleScreen(o.PositionX, o.PositionY)); foreach (var celestialObject in objectsInScreenArea) { var objectLocation = GetCurrentLocation(granularTurnInformation, celestialObject, turnStep, screenParameters.DrawInterval); var shipLocation = GetCurrentLocation(granularTurnInformation, playerSpaceship, turnStep, screenParameters.DrawInterval); var directionFromShipToTarget = Coordinates.GetRotation(objectLocation, shipLocation); var directionFromTargetToShip = Coordinates.GetRotation(shipLocation, objectLocation); var shipLocationStep = SpaceMapTools.Move(shipLocation, 12, 0, directionFromShipToTarget); var targetLocationStep = SpaceMapTools.Move(objectLocation, 20, 0, directionFromTargetToShip); var shipScreenCoordinates = UI.ToScreenCoordinates(screenParameters, new PointF(shipLocationStep.PointTo.X, shipLocationStep.PointTo.Y)); var objectScreenCoordinates = UI.ToScreenCoordinates(screenParameters, new PointF(targetLocationStep.PointTo.X, targetLocationStep.PointTo.Y)); var targetScreenCoordinates = UI.ToScreenCoordinates(screenParameters, new PointF(objectLocation.X, objectLocation.Y)); graphics.DrawLine(connectorPen, shipScreenCoordinates.X, shipScreenCoordinates.Y, objectScreenCoordinates.X, objectScreenCoordinates.Y); graphics.DrawEllipse(connectorPen, targetScreenCoordinates.X - 20, targetScreenCoordinates.Y - 20, 40, 40); } }
public static void DrawSpaceShipMovement(Graphics graphics, GameSession gameSession, SortedDictionary <int, GranularObjectInformation> turnMapInformation, int turnStep, FixedSizedQueue <SortedDictionary <int, GranularObjectInformation> > history, ScreenParameters screenParameters) { var playerSpaceship = gameSession.GetPlayerSpaceShip(); #region Direction forward foreach (var turnInformation in turnMapInformation.Values) { if (playerSpaceship.Id == turnInformation.CelestialObject.Id) { continue; } if (gameSession.GetCelestialObject(turnInformation.CelestialObject.Id).IsSpaceship() == false) { return; } var currentObject = turnInformation.CelestialObject; var location = GetCurrentLocation(turnMapInformation, currentObject, turnStep, screenParameters.DrawInterval).ToScreen(screenParameters); var step = SpaceMapTools.Move(location, 4000, 0, currentObject.Direction); graphics.DrawLine(new Pen(Color.FromArgb(24, 24, 24)), step.PointFrom, step.PointTo); } #endregion #region Direction back foreach (var turnInformation in turnMapInformation.Values) { if (turnInformation.CelestialObject.IsSpaceship() == false) { continue; } var currentObject = turnInformation.CelestialObject; var points = new List <PointF>(); var data = history.GetData(); var turnId = 0; foreach (var turnData in data) { var stepId = 0; foreach (var wayPoint in turnData[currentObject.Id].WayPoints.Values) { if (turnId > 0 || stepId > turnStep) { points.Add(wayPoint.ToScreen(screenParameters)); } stepId++; } turnId++; } if (points.Count > 2) { graphics.DrawCurve(new Pen(Color.FromArgb(200, 44, 44)) { DashStyle = DashStyle.Dash }, points.ToArray()); } } #endregion }
public static List <SpaceMapObjectLocation> CalculateIteration(PointF currentLocation, PointF targetLocation, double direction, double speed, int maxIterations = 2000) { const int agility = 5; var result = new List <SpaceMapObjectLocation>(); // In this case first iteration - start position for calculation. var previousIteration = new SpaceMapObjectLocation { Distance = SpaceMapTools.GetDistance(targetLocation, currentLocation), Direction = direction, Status = MovementType.Default, Coordinates = new PointF(currentLocation.X, currentLocation.Y) }; var currentStepInTurn = speed; for (var iteration = 0; iteration < maxIterations; iteration++) { var location = SpaceMapTools.Move(previousIteration.Coordinates.ToVector2(), 1, previousIteration.Direction); var iterationResult = new SpaceMapObjectLocation { Direction = previousIteration.Direction, Iteration = iteration, Coordinates = location.PointTo, Distance = SpaceMapTools.GetDistance(targetLocation, location.PointTo) }; // 0 - 360 degree var attackAzimuth = SpaceMapTools.GetAngleBetweenPoints(location.PointTo.ToVector2(), targetLocation.ToVector2()); // Turn angle var attackAngle = (int)SpaceMapTools.GetRotateDirection(iterationResult.Direction, attackAzimuth); var currentAgility = 0; if (speed == currentStepInTurn) { currentAgility = agility; } currentStepInTurn++; if (currentStepInTurn > speed) { currentStepInTurn = 0; } switch (attackAngle) { case var _ when attackAngle > 0: // > 0 left turn iterationResult.Direction -= currentAgility; iterationResult.Status = MovementType.Turn; break; case var _ when attackAngle < 0: // < 0 right turn iterationResult.Direction += currentAgility; iterationResult.Status = MovementType.Turn; break; case var _ when attackAngle == 0: // = 0 forward iterationResult.Status = MovementType.Linear; break; } if (iterationResult.Distance >= 2) { result.Add(iterationResult); } else { result.Add(iterationResult); break; } result.Add(iterationResult); previousIteration = iterationResult; } //result.Add(new SpaceMapObjectLocation { ScanRange = 0, Direction = direction, Iteration = result.Count, Coordinates = targetLocation }); return(result); }
public static Result Calculate(PointF currentLocation, PointF targetLocation, double direction, double speed, int maxIterations = 2000) { const int agility = 5; var result = new Result(); // In this case first iteration - start position for calculation. var previousIteration = new SpaceMapObjectLocation { Distance = SpaceMapTools.GetDistance(targetLocation, currentLocation), Direction = direction, Status = MovementType.Default, Coordinates = new PointF(currentLocation.X, currentLocation.Y) }; var currentStepInTurn = speed; for (var iteration = 0; iteration < maxIterations; iteration++) { var location = SpaceMapTools.Move(previousIteration.Coordinates.ToVector2(), 1, previousIteration.Direction); var iterationResult = new SpaceMapObjectLocation { Direction = previousIteration.Direction, Iteration = iteration, Coordinates = location.PointTo, Distance = SpaceMapTools.GetDistance(targetLocation, location.PointTo) }; // 0 - 360 degree var attackAzimuth = SpaceMapTools.GetAngleBetweenPoints(location.PointTo.ToVector2(), targetLocation.ToVector2()); // Turn angle var attackAngle = SpaceMapTools.GetRotateDirection(iterationResult.Direction, attackAzimuth); var currentAgility = 0; if ((int)speed == (int)currentStepInTurn) { currentAgility = agility; if (Math.Abs(attackAngle) < agility) { attackAngle = 0; iterationResult.Direction = attackAzimuth; } } currentStepInTurn++; if (currentStepInTurn > speed) { currentStepInTurn = 0; } switch (attackAngle) { case var _ when attackAngle > 1: // > 0 left turn iterationResult.Direction -= currentAgility; iterationResult.Status = MovementType.Turn; break; case var _ when attackAngle < -1: // < 0 right turn iterationResult.Direction += currentAgility; iterationResult.Status = MovementType.Turn; break; case var _ when attackAngle == 0: // = 0 forward iterationResult.Status = MovementType.Linear; break; case var _ when attackAngle == 1: // = 0 forward iterationResult.Status = MovementType.Linear; break; } if (iterationResult.Distance >= 2) { result.Trajectory.Add(iterationResult); } else { result.Trajectory.Add(iterationResult); break; } iterationResult.Direction = iterationResult.Direction.To360Degrees(); result.Trajectory.Add(iterationResult); previousIteration = iterationResult; if (iterationResult.Status == MovementType.Linear) { var linearIteration = 0; foreach (var points in LinearMovement(iterationResult.Coordinates, targetLocation)) { linearIteration++; result.Trajectory.Add(new SpaceMapObjectLocation { Coordinates = points, Distance = SpaceMapTools.GetDistance(targetLocation, points), Direction = iterationResult.Direction.To360Degrees(), Status = MovementType.Linear, Iteration = iterationResult.Iteration + linearIteration }); } break; } } return(result); }