Ejemplo n.º 1
0
 void MoveQuadInput(QuadPressed quadToMove)
 {
     if (state == PuzzleState.InPlay)
     {
         //    Enqueue puts stuff in the queue
         inputs.Enqueue(quadToMove);
         NextMove();
     }
 }
Ejemplo n.º 2
0
    void CreateGrid()
    {
        //8.a
        quads = new QuadPressed[quadsPerLine, quadsPerLine];
        //6.a
        Texture2D[,] imgSlice = gridPicture.GetSlice(img, quadsPerLine);

        //2.    CREATE puzzle by adding squares on the x/y axes.
        for (int y = 0; y < quadsPerLine; y++)
        {
            for (int x = 0; x < quadsPerLine; x++)
            {
                GameObject quadObject = GameObject.CreatePrimitive(PrimitiveType.Quad);
                //    tried with plane. Quad is cleaner.
                //    center the grid:
                quadObject.transform.position = -Vector2.one * (quadsPerLine - 1) * 0.5f + new Vector2(x, y);
                quadObject.transform.parent   = transform;

                //2.5???    adds the QuadPressed function/action/whatever to the grid we're makin' <-- that's my southern accent.  "makin'"
                QuadPressed quadPressed = quadObject.AddComponent <QuadPressed>();

                quadPressed.OnQuadPressed    += MoveQuadInput;
                quadPressed.OnFinishedMoving += OnQuadFinishedMoving;
                //7.a    QuadPressed initializes start coord and text2d slice
                quadPressed.Init(new Vector2Int(x, y), imgSlice[x, y]);
                //8.b
                quads[x, y] = quadPressed;

                //3.a    if there's an empty space...
                if (y == 0 && x == quadsPerLine - 1)
                {
                    //slidingSquares.SetActive(false);
                    emptyQuad = quadPressed;
                }
                //#IDK?
            }
        }

        Camera.main.orthographicSize = quadsPerLine * .55f;
        inputs = new Queue <QuadPressed>();
    }
Ejemplo n.º 3
0
    //4. SWAP the position of the emptyQuad with the quadPressed
    void MoveQuad(QuadPressed quadToMove, float duration)
    {
        //5. LIMIT swap positions to adjacent quads
        //    wtf how do i even
        //    ...10 tutorials later...
        if ((quadToMove.coord - emptyQuad.coord).sqrMagnitude == 1)
        {
            //9.b Swap positions in array
            quads[quadToMove.coord.x, quadToMove.coord.y] = emptyQuad;
            quads[emptyQuad.coord.x, emptyQuad.coord.y]   = quadToMove;

            Vector2Int targetCoord = emptyQuad.coord;
            emptyQuad.coord  = quadToMove.coord;
            quadToMove.coord = targetCoord;

            //    position to move the pressedQuad to.
            Vector2 targetPosition = emptyQuad.transform.position;
            emptyQuad.transform.position = quadToMove.transform.position;
            //    swap the position of the emptyQuad and the quadPressed
            quadToMove.MoveToPosition(targetPosition, duration);  //duration: .3f);
            quadIsMoving = true;
        }
    }