private List <Vector2> FormListOfCrossedPoints(Vector2 playerPos, PathDirections pathDirections) { List <Vector2> crossedPoints = new List <Vector2>(); List <int> crossedPointIndexes = new List <int>(); for (int i = 0; i < colliderPaths.Count; i++) { Vector2[] path = colliderPaths[i]; for (int j = 0; j < path.Length; j++) { int k = j == path.Length - 1 ? 0 : j + 1; bool isCrossed = isLinesIntersected(playerPos, mousePos, path[j], path[k]); if (pathDirections == PathDirections.RightAngled && isCrossed) { CheckRightAngledCrossing(playerPos, crossedPointIndexes, path, j, k); } if (pathDirections == PathDirections.LeftAngled && isCrossed) { CheckLeftAngledCrossing(playerPos, crossedPointIndexes, path, j, k); } } crossedPoints = GetReformedPointsList(crossedPoints, crossedPointIndexes, path); } return(crossedPoints); }
public PathOrientation(JToken json) { var pointOffset = (int)json[JsonNames.PointOffset]; var pathDirection = (PathDirections)Enum.Parse(typeof(PathDirections), (string)json[JsonNames.PathDirection]); m_pointOffset = pointOffset; m_pathDirection = pathDirection; }
public void Flip() { if (PathDirection == PathDirections.Clockwise) { PathDirection = PathDirections.Counterclockwise; } else { PathDirection = PathDirections.Clockwise; } }
private void CheckDistanceToTarget(List <Vector2> path) { if (path.Count < 2) { return; } Vector2 lastPoint = path[path.Count - 1]; Vector2 preLastPoint = path[path.Count - 2]; float distanceFromPrevPoint = Vector2.Distance(preLastPoint, mousePos); float distanceFromLastPoint = Vector2.Distance(lastPoint, mousePos) + Vector2.Distance(preLastPoint, lastPoint); PathDirections pathDirection = DefineDirections(preLastPoint); List <Vector2> crossedPoints = FormListOfCrossedPoints(preLastPoint, pathDirection); ChechIfPointLinesCrossed(lastPoint, preLastPoint, distanceFromPrevPoint, distanceFromLastPoint, crossedPoints); }
private PathDirections DefineDirections(Vector2 playerPos) { PathDirections pathDirection = PathDirections.LeftAngled; if (playerPos.x >= mousePos.x && playerPos.y > mousePos.y || playerPos.x <= mousePos.x && playerPos.y < mousePos.y) { pathDirection = PathDirections.RightAngled; } else if (playerPos.x < mousePos.x && playerPos.y >= mousePos.y || playerPos.x > mousePos.x && playerPos.y <= mousePos.y) { pathDirection = PathDirections.LeftAngled; } return(pathDirection); }
private void CreatePlayerPath(Vector2 playerPos) { mousePos = GetRightMousePosition(); PathDirections pathDirection = DefineDirections(playerPos); List <Vector2> crossedPoints = FormListOfCrossedPoints(playerPos, pathDirection); if (crossedPoints.Count == 0) { target = mousePos; } else { FormFinalPath(playerPos, crossedPoints); animator.SetBool(PATH, true); isPathCreated = true; } }
public void AddPath(List <Direction> path) { PathDirections.Add(path); }
public PathOrientation(int pointOffset, PathDirections pathDirection) { m_pointOffset = pointOffset; m_pathDirection = pathDirection; }