コード例 #1
0
    private static void MergeNearByPointLines(LevelSkeleton skeleton)
    {
        SkeletonLine lineToRemove1 = null;
        var          isStart       = true;

        var attempts = 0;

        while ((lineToRemove1 != null || isStart) && attempts <= GeneratorConstants.MaxGenerationAttempts)
        {
            isStart       = false;
            lineToRemove1 = null;

            foreach (var point in skeleton.Points)
            {
                var lineToRemove = skeleton.Lines.Where(l => !l.ContainsSkeletonPoint(point) && l.GetDistanceBetweenLineAndPoint(point) < 5)
                                   .FirstOrDefault();

                if (lineToRemove != null)
                {
                    var l1 = !skeleton.LinesForPoint(point).Any(_ => _.ContainsSkeletonPoint(lineToRemove.Points.pointA))
                        ? new SkeletonLine(point, lineToRemove.Points.pointA)
                        : null;

                    var l2 = !skeleton.LinesForPoint(point).Any(_ => _.ContainsSkeletonPoint(lineToRemove.Points.pointB))
                        ? new SkeletonLine(point, lineToRemove.Points.pointB)
                        : null;

                    if (l1 != null)
                    {
                        skeleton.AddLine(l1);
                        point.Type    = new EntityType(Color.red, "NearByLine");
                        lineToRemove1 = lineToRemove;
                    }

                    if (l2 != null)
                    {
                        skeleton.AddLine(l2);
                        point.Type    = new EntityType(Color.red, "NearByLine");
                        lineToRemove1 = lineToRemove;
                    }

                    if (lineToRemove1 != null)
                    {
                        break;
                    }
                }
            }

            attempts++;
            skeleton.RemoveLines(new List <SkeletonLine> {
                lineToRemove1
            });
        }

        if (attempts > GeneratorConstants.MaxGenerationAttempts)
        {
            Debug.Log("Too many attempts");
        }
    }
コード例 #2
0
    private static void ReplaceMoreThan45(LevelSkeleton skeleton)
    {
        var linesToRemove = new List <SkeletonLine>();

        skeleton.Lines.ToList().ForEach(_ =>
        {
            if (!(_.GetLineAngle() > 45))
            {
                return;
            }

            var point = new SkeletonPoint(new Vector2(_.Points.pointA.Position.x, _.Points.pointB.Position.y), new EntityType(Color.blue, "Additional"));
            var line1 = new SkeletonLine(_.Points.pointA, point, new EntityType(Color.green, "Corrected"));
            var line2 = new SkeletonLine(_.Points.pointB, point, new EntityType(Color.green, "Corrected"));

            skeleton.AddLine(line1);
            skeleton.AddLine(line2);
            linesToRemove.Add(_);
        });

        skeleton.RemoveLines(linesToRemove);
    }
コード例 #3
0
 public static float?GetDistanceBetweenLineAndPoint(this SkeletonLine line, SkeletonPoint point)
 => line.ToVector2().GetDistanceBetweenLineAndPoint(point.Position);
コード例 #4
0
    public static IEnumerable <LevelWall> GetLevelWalls(this SkeletonLine skeletonLine)
    {
        const float width = 3f;

        if (skeletonLine.Type.Name == EntityTypeConstants.Floor.Name || skeletonLine.Type.Name == EntityTypeConstants.Elevator.Name)
        {
            var(wallA, wallB) = GetWalls(skeletonLine, width);

            return(new List <LevelWall> {
                wallA, wallB
            });
        }

        if (skeletonLine.Type == EntityTypeConstants.EmptySpaceFloor)
        {
            var(wallA, wallB) = GetWalls(skeletonLine, width);
            var wall = wallA.Points.pointA.y < wallB.Points.pointA.y
                ? wallA
                : wallB;

            return(new List <LevelWall> {
                wall
            });
        }

        if (skeletonLine.Type == EntityTypeConstants.EmptySpaceTop)
        {
            var(wallA, wallB) = GetWalls(skeletonLine, width);
            var wall = wallA.Points.pointA.y > wallB.Points.pointA.y
                ? wallA
                : wallB;

            var airPlatform = wallA.Points.pointA.y <= wallB.Points.pointA.y
                ? wallA
                : wallB;

            airPlatform.Type = EntityTypeConstants.AirPlatform;

            return(new List <LevelWall> {
                wall, airPlatform
            });
        }

        if (skeletonLine.Type == EntityTypeConstants.EmptySpaceElevatorLeft)
        {
            var(wallA, wallB) = GetWalls(skeletonLine, width);
            var wall = wallA.Points.pointA.x < wallB.Points.pointA.x
                ? wallA
                : wallB;

            return(new List <LevelWall> {
                wall
            });
        }

        if (skeletonLine.Type == EntityTypeConstants.EmptySpaceElevatorRight)
        {
            var(wallA, wallB) = GetWalls(skeletonLine, width);
            var wall = wallA.Points.pointA.x > wallB.Points.pointA.x
                ? wallA
                : wallB;

            return(new List <LevelWall> {
                wall
            });
        }

        if (skeletonLine.Type == EntityTypeConstants.InsideFloor)
        {
            var(wallA, wallB) = GetWalls(skeletonLine, width);
            var wall = wallA.Points.pointA.y < wallB.Points.pointA.y
                ? wallA
                : wallB;

            wall.Type = EntityTypeConstants.AirPlatform;
            return(new List <LevelWall> {
                wall
            });
        }

        return(new List <LevelWall>());
    }
コード例 #5
0
 //  Returns Point of intersection if do intersect otherwise default Point (null)
 public static Vector2?FindIntersection(this SkeletonLine lineA, SkeletonLine lineB)
 => lineA.ToVector2().FindIntersection(lineB.ToVector2());
コード例 #6
0
 public static SkeletonPoint GetMiddlePoint(this SkeletonLine line)
 => new SkeletonPoint(line.ToVector2().GetMiddlePoint());
コード例 #7
0
 public static (Vector2 pointA, Vector2 pointB) ToVector2(this SkeletonLine skeletonLine)
 => (skeletonLine.Points.pointA.Position, skeletonLine.Points.pointB.Position);
コード例 #8
0
 public static LevelElevator GetLevelElevator(this SkeletonLine skeletonLine)
 => skeletonLine.Type.Name.Contains("Elevator")
      ? new LevelElevator(skeletonLine.Points.pointA.Position, skeletonLine.Points.pointB.Position, EntityTypeConstants.Elevator)
      : null;
コード例 #9
0
 public static double GetOriginalLineAngle(this SkeletonLine line)
 => line.ToVector2().GetOrigianlLineAngle();
コード例 #10
0
 public void AddLine(SkeletonLine newLine)
 {
     AddLines(new List <SkeletonLine> {
         newLine
     });
 }
コード例 #11
0
 public void RemoveLine(SkeletonLine line)
 {
     _lines.Remove(line);
 }
コード例 #12
0
 public void AddLine(SkeletonLine line)
 {
     _lines.Add(line);
 }