Exemplo n.º 1
0
        public static MarchDirections EdgeToSolutionDir(LevelEdge edge)
        {
            //This code is contained in the GetSolutionsForEdge function but i needed it elsewhere too
            //f**k this is messy.
            MarchDirections mdir = MarchDirections.positiveSlope_left;

            if (edge == LevelEdge.top)
            {
                mdir = MarchDirections.positiveSlope_left;
            }
            else if (edge == LevelEdge.topRight)
            {
                mdir = MarchDirections.positiveSlope_left;
            }
            else if (edge == LevelEdge.topLeft)
            {
                mdir = MarchDirections.horizontal_right;
            }
            else if (edge == LevelEdge.bottom)
            {
                mdir = MarchDirections.negativeSlope_left;
            }
            else if (edge == LevelEdge.bottomRight)
            {
                mdir = MarchDirections.negativeSlope_left;
            }
            else if (edge == LevelEdge.bottomLeft)
            {
                mdir = MarchDirections.horizontal_right;
            }
            return(mdir);
        }
Exemplo n.º 2
0
    public Vector3 Load(LevelEdge levelEdge, int levelId, Vector3 startpos)
    {
        edge = LevelResManager.Instance.GetEdge(levelId, levelEdge.edgeType);
        //edge.transform.position = levelEdge.GetPosition (LevelManager.h1,LevelManager.h2);

        Vector3 local = startpos;

        local.x = local.x + edge.getXSize() * 0.5f;
        local.y = local.y + edge.getYSize() * 0.5f;
        edge.gameObject.transform.position = local;
        startpos.x = startpos.x + edge.getXSize();

        return(startpos);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 创建一个水平的level
    /// </summary>
    public void CreateLevel2()
    {
        step  = Random.Range(4, 6);
        first = 0;
        LevelNode start = new LevelNode();

        start.Index2 = first;
        start.left   = false;
        start.right  = true;
        start.type   = eNodeType.Start;
        levelNodes.Add(start);

        LevelNode tmp = start;

        for (int i = 1; i < step; i++)
        {
            LevelNode node = new LevelNode();
            node.Index2 = i;
            if (i == step - 1)
            {
                node.left  = true;
                node.right = false;
                node.type  = eNodeType.End;
            }
            else
            {
                node.left  = true;
                node.right = true;
                node.type  = eNodeType.Normal;
            }
            levelNodes.Add(node);

            LevelEdge edge = new LevelEdge(node, tmp);
            tmp = node;
            levelEdges.Add(edge);
        }

        //Init();
        //CreateLevel();
    }
Exemplo n.º 4
0
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="start">Start point of the edge</param>
 /// <param name="end">End point of the edge</param>
 /// <param name="isDoubleSided">true if this edge is double-sided</param>
 /// <param name="srcEdge">Source edge</param>
 public Edge( Point2 start, Point2 end, bool isDoubleSided, LevelEdge srcEdge )
 {
     m_Start = start;
     m_End = end;
     m_IsDoubleSided = isDoubleSided;
     m_SourceEdge = srcEdge;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Setup constructor
 /// </summary>
 public Edge( LevelEdge srcEdge )
 {
     m_Start = srcEdge.Start.Position;
     m_End = srcEdge.End.Position;
     m_IsDoubleSided = srcEdge.IsDoubleSided;
     m_SourceEdge = srcEdge;
 }
Exemplo n.º 6
0
 private static Vector2 EdgeNormal( LevelEdge edge, bool reverse )
 {
     if ( !reverse )
     {
         return ( edge.End.Position - edge.Start.Position ).MakePerpNormal( );
     }
     return ( edge.Start.Position - edge.End.Position ).MakePerpNormal( );
 }
Exemplo n.º 7
0
        /// <summary>
        /// Addges edges from a LevelEdge list to an Edge list. Pushes the edges out to a given distance, and adds a chamfer
        /// </summary>
        private static void AddExpandedEdges( LevelEdge[] sourceEdges, IList< Edge > edges, float distance, bool reverse )
        {
            float sgnDistance = ( reverse ? distance : -distance );
            Vector2 curNormal = EdgeNormal( sourceEdges[ 0 ], reverse );
            Point2 newStartPt = sourceEdges[ 0 ].Start.Position + ( curNormal * sgnDistance );

            for ( int sourceEdgeIndex = 0; sourceEdgeIndex < sourceEdges.Length; ++sourceEdgeIndex )
            {
                LevelEdge sourceEdge = sourceEdges[ sourceEdgeIndex ];
                LevelEdge nextSourceEdge = sourceEdges[ ( sourceEdgeIndex + 1 ) % sourceEdges.Length ];
                Vector2 nextNormal = EdgeNormal( nextSourceEdge, reverse );

                //	Calculate the chamfer point, or edge meeting point
                Point2 chPos = sourceEdge.End.Position + ( ( curNormal + nextNormal ).MakeNormal( ) * sgnDistance );

                float pdp = curNormal.DotPerp( nextNormal );
            //	if ( reverse ? pdp > -0.001f : pdp < 0.001f )
                if ( pdp > -0.001f )
                {
                    //	Facing edges - no chamfer needed
                    // x---V---x
                    // ........|
                    //        .<
                    //        .|
                    //        .x	(dots indicate new edges)

                    //	Add expanded edge
                    Edge edge = new Edge( newStartPt, chPos, sourceEdge.IsDoubleSided, sourceEdge );
                    edges.Add( edge );

                    newStartPt = chPos;

                    //	If this is the last edge, then reset the start position of the first edge
                    if ( sourceEdgeIndex == ( sourceEdges.Length - 1 ) )
                    {
                        edges[ 0 ].Start = chPos;
                    }
                }
                else
                {
                    //	Non-facing edges - create chamfer
                    // ..........
                    // x---^---x.
                    //         |.
                    //         >.
                    //         |.
                    //         x.	(dots indicate new edges)

                    //	Calculate expanded edge end point
                    Point2 exEnd = sourceEdge.End.Position + ( curNormal * sgnDistance );

                    //	Add expanded edge
                    Edge edge = new Edge( newStartPt, exEnd, sourceEdge.IsDoubleSided, sourceEdge );
                    edges.Add( edge );

                    //	Add chamfer edge joining the end of the current edge to the chamfer point
                    Edge chEdge = new Edge( exEnd, chPos, sourceEdge.IsDoubleSided, sourceEdge );
                    edges.Add( chEdge );

                    //	Add chamfer edge joining the chamfer point to the start of the next edge
                    newStartPt = nextSourceEdge.Start.Position + ( nextNormal * sgnDistance );
                    chEdge = new Edge( chPos, newStartPt, nextSourceEdge.IsDoubleSided, nextSourceEdge );
                    edges.Add( chEdge );
                }

                curNormal = nextNormal;
            }
        }
Exemplo n.º 8
0
        public int[][] GetSolutionsForEdge(LevelEdge edge, Dictionary <Vector2Int, int> level)
        {
            MarchDirections mdir          = MarchDirections.horizontal_right;
            List <Triangle> edgeTriangles = new List <Triangle>();

            //
            if (edge == LevelEdge.top)
            {
                edgeTriangles = topEdgeTriangles;
                mdir          = MarchDirections.positiveSlope_left;
            }
            else if (edge == LevelEdge.topRight)
            {
                edgeTriangles = topRightEdgeTriangles;
                mdir          = MarchDirections.positiveSlope_left;
            }
            else if (edge == LevelEdge.topLeft)
            {
                edgeTriangles = topLeftEdgeTriangles;
                mdir          = MarchDirections.horizontal_right;
            }
            else if (edge == LevelEdge.bottom)
            {
                edgeTriangles = bottomEdgeTriangles;
                mdir          = MarchDirections.negativeSlope_left;
            }
            else if (edge == LevelEdge.bottomRight)
            {
                edgeTriangles = bottomRightEdgeTriangles;
                mdir          = MarchDirections.negativeSlope_left;
            }
            else if (edge == LevelEdge.bottomLeft)
            {
                edgeTriangles = bottomLeftEdgeTriangles;
                mdir          = MarchDirections.horizontal_right;
            }


            int[][] solutions = new int[edgeTriangles.Count][];//our array of arrays.
            // for(int i = edgeTriangles.Count-1;i>0;i--){
            foreach (Triangle mt in edgeTriangles)
            {
                // Triangle mt = edgeTriangles[i];//-1-i

                Vector2Int        m         = mt.position;
                List <Vector2Int> trisInRow = new List <Vector2Int>();
                List <int>        solution  = new List <int>();
                solution.Add(level[m]);
                trisInRow.Add(m);
                bool marching = true;
                while (marching)
                {
                    Vector2Int key = Triangle.March(m, mdir);
                    if (level.ContainsKey(key))
                    {
                        m = key;//key is in while, m is out of this scope.
                        solution.Add(level[m]);
                        trisInRow.Add(m);
                    }
                    else
                    {
                        marching = false;
                    }
                }
                // solutions[i] = solution.ToArray();
                edgeTriangleToRowOfTrianglesMap.Add(mt.position, trisInRow.ToArray());//used for hint comparisons.
                edgeTriangleToSolutionMap.Add(mt, solution.ToArray());
            }
            //
            return(solutions);
        }
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="pt">Initial position of the vertex</param>
 public LevelVertex( Point2 pt )
 {
     m_Position = pt;
     m_StartEdge = null;
     m_EndEdge = null;
 }
Exemplo n.º 10
0
    public void CreateNextLevelNode(LevelNode last)
    {
        List <int> arounds = last.GetAround();

        for (int i = arounds.Count - 1; i >= 0; i--)
        {
            if (IsInLevelNodes(arounds [i]))
            {
                arounds.RemoveAt(i);
            }
        }
        if (arounds.Count <= 0)
        {
            return;
        }
        int       select = Random.Range(0, arounds.Count);
        LevelNode node   = new LevelNode();

        node.Index = arounds[select];
        levelNodes.Add(node);
        select = node.Index;

        List <int> tmparounds = node.GetAround();

        for (int i = 0; i < tmparounds.Count; i++)
        {
            int nodeindex = tmparounds [i];
            if (IsInLevelNodes(nodeindex))
            {
                if (step == stepindex - 1 || ((step < stepindex - 1 && step > 1) && (nodeindex != first)) || ((step == 1) && (nodeindex == last.Index)))
                {
                    eNodeDirType nodedirtype = LevelNode.GetRelation(nodeindex, select);
                    LevelNode    tmp         = GetLevelNode(nodeindex);
                    LevelEdge    edge        = new LevelEdge(node, tmp);
                    levelEdges.Add(edge);
                    switch (nodedirtype)
                    {
                    case eNodeDirType.right:
                    {
                        node.left = true;
                        tmp.right = true;
                        break;
                    }

                    case eNodeDirType.left:
                    {
                        node.right = true;
                        tmp.left   = true;
                        break;
                    }

                    case eNodeDirType.top:
                    {
                        node.bottom = true;
                        tmp.top     = true;
                        break;
                    }

                    case eNodeDirType.bottom:
                    {
                        tmp.bottom = true;
                        node.top   = true;
                        break;
                    }

                    default:
                        break;
                    }
                }
            }
        }

        if (step == 1)
        {
            node.type = eNodeType.End;
        }
        step--;
        if (step > 0)
        {
            CreateNextLevelNode(node);
        }
    }