public SpawnPosition(GraphEdge graphEdge, Vector2 normal, LevelObjectPrefab.SpawnPosType spawnPosType, Alignment alignment)
            {
                GraphEdge    = graphEdge;
                Normal       = normal;
                SpawnPosType = spawnPosType;
                Alignment    = alignment;

                Length = Vector2.Distance(graphEdge.Point1, graphEdge.Point2);
            }
            public SpawnPosition(GraphEdge graphEdge, Vector2 normal, LevelObjectPrefab.SpawnPosType spawnPosType, Alignment alignment)
            {
                GraphEdge    = graphEdge;
                Normal       = normal;
                SpawnPosType = spawnPosType;
                Alignment    = alignment;

                Length = Vector2.Distance(graphEdge.Point1, graphEdge.Point2);

                noiseVal =
                    (float)(PerlinNoise.CalculatePerlin(GraphEdge.Point1.X / 10000.0f, GraphEdge.Point1.Y / 10000.0f, 0.5f) +
                            PerlinNoise.CalculatePerlin(GraphEdge.Point1.X / 20000.0f, GraphEdge.Point1.Y / 20000.0f, 0.5f));
            }
        private List <SpawnPosition> GetAvailableSpawnPositions(IEnumerable <VoronoiCell> cells, LevelObjectPrefab.SpawnPosType spawnPosType)
        {
            List <SpawnPosition> availableSpawnPositions = new List <SpawnPosition>();

            foreach (var cell in cells)
            {
                foreach (var edge in cell.Edges)
                {
                    if (!edge.IsSolid || edge.OutsideLevel)
                    {
                        continue;
                    }
                    Vector2 normal = edge.GetNormal(cell);

                    Alignment edgeAlignment = 0;
                    if (normal.Y < -0.5f)
                    {
                        edgeAlignment |= Alignment.Bottom;
                    }
                    else if (normal.Y > 0.5f)
                    {
                        edgeAlignment |= Alignment.Top;
                    }
                    else if (normal.X < -0.5f)
                    {
                        edgeAlignment |= Alignment.Left;
                    }
                    else if (normal.X > 0.5f)
                    {
                        edgeAlignment |= Alignment.Right;
                    }

                    availableSpawnPositions.Add(new SpawnPosition(edge, normal, spawnPosType, edgeAlignment));
                }
            }
            return(availableSpawnPositions);
        }
        private List <SpawnPosition> GetAvailableSpawnPositions(IEnumerable <VoronoiCell> cells, LevelObjectPrefab.SpawnPosType spawnPosType)
        {
            List <LevelObjectPrefab.SpawnPosType> spawnPosTypes = new List <LevelObjectPrefab.SpawnPosType>(4);
            List <SpawnPosition> availableSpawnPositions        = new List <SpawnPosition>();

            foreach (var cell in cells)
            {
                foreach (var edge in cell.Edges)
                {
                    if (!edge.IsSolid || edge.OutsideLevel)
                    {
                        continue;
                    }
                    if (spawnPosType != LevelObjectPrefab.SpawnPosType.CaveWall && edge.NextToCave)
                    {
                        continue;
                    }
                    Vector2 normal = edge.GetNormal(cell);

                    Alignment edgeAlignment = 0;
                    if (normal.Y < -0.5f)
                    {
                        edgeAlignment |= Alignment.Bottom;
                    }
                    else if (normal.Y > 0.5f)
                    {
                        edgeAlignment |= Alignment.Top;
                    }
                    else if (normal.X < -0.5f)
                    {
                        edgeAlignment |= Alignment.Left;
                    }
                    else if (normal.X > 0.5f)
                    {
                        edgeAlignment |= Alignment.Right;
                    }

                    spawnPosTypes.Clear();
                    spawnPosTypes.Add(spawnPosType);
                    if (spawnPosType.HasFlag(LevelObjectPrefab.SpawnPosType.MainPathWall) && edge.NextToMainPath)
                    {
                        spawnPosTypes.Add(LevelObjectPrefab.SpawnPosType.MainPathWall);
                    }
                    if (spawnPosType.HasFlag(LevelObjectPrefab.SpawnPosType.SidePathWall) && edge.NextToSidePath)
                    {
                        spawnPosTypes.Add(LevelObjectPrefab.SpawnPosType.SidePathWall);
                    }
                    if (spawnPosType.HasFlag(LevelObjectPrefab.SpawnPosType.CaveWall) && edge.NextToCave)
                    {
                        spawnPosTypes.Add(LevelObjectPrefab.SpawnPosType.CaveWall);
                    }

                    availableSpawnPositions.Add(new SpawnPosition(edge, normal, spawnPosTypes, edgeAlignment));
                }
            }
            return(availableSpawnPositions);
        }
 public SpawnPosition(GraphEdge graphEdge, Vector2 normal, LevelObjectPrefab.SpawnPosType spawnPosType, Alignment alignment)
     : this(graphEdge, normal, spawnPosType.ToEnumerable(), alignment)
 {
 }