Beispiel #1
0
    public void Clicked()
    {
        if (!Board.PlayerCanMove ||
            currentStrenght == TileType.BlockedTile ||
            currentStrenght == TileType.TodoExtraStrong ||
            currentStrenght == TileType.TodoStrong ||
            currentStrenght == TileType.TodoSuperStrong)
        {
            Debug.Log("Current Strenght=" + currentStrenght);
            return;
        }
        _Gp1 = GridPositions.GetGridPosition(new Vector2(myTransform.position.x, myTransform.position.y));
        if (_Gp1.x != -1 && Board.ActivePiece.x == -1)
        {
            Board.ActivePiece = _Gp1;
        }
        else if (_Gp1.x != -1)
        {
            if (Board.Instance.gameStyle == GameStyle.Standard && Mathf.Abs(_Gp1 - Board.ActivePiece) > 1)
            {
                Board.ActivePiece = _Gp1;
                return;
            }

            if (
                (!Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX(_Gp1.x, _Gp1.y, Board.ActivePiece.x, Board.ActivePiece.y, true)) ||
                  (Board.Instance.CheckTileMatchX(Board.ActivePiece.x, Board.ActivePiece.y, _Gp1.x, _Gp1.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp1.x, _Gp1.y, Board.ActivePiece.x, Board.ActivePiece.y, true)) ||
                  (Board.Instance.CheckTileMatchY(Board.ActivePiece.x, Board.ActivePiece.y, _Gp1.x, _Gp1.y, true)))) ||
                (Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX4(_Gp1.x, _Gp1.y, Board.ActivePiece.x, Board.ActivePiece.y, true)) ||
                  (Board.Instance.CheckTileMatchX4(Board.ActivePiece.x, Board.ActivePiece.y, _Gp1.x, _Gp1.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp1.x, _Gp1.y, Board.ActivePiece.x, Board.ActivePiece.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(Board.ActivePiece.x, Board.ActivePiece.y, _Gp1.x, _Gp1.y, true))))
                )
            {
                MoveTo(Board.ActivePiece.x, Board.ActivePiece.y);
                Board.PlayingPieces[Board.ActivePiece.x, Board.ActivePiece.y].pieceScript.MoveTo(_Gp1.x, _Gp1.y);
                Board.PlayingPieces[_Gp1.x, _Gp1.y].Active = true;
                Board.PlayingPieces[Board.ActivePiece.x, Board.ActivePiece.y].Active = false;
                PlayingPiece tmp = Board.PlayingPieces[_Gp1.x, _Gp1.y];
                Board.PlayingPieces[_Gp1.x, _Gp1.y] = Board.PlayingPieces[Board.ActivePiece.x, Board.ActivePiece.y];
                Board.PlayingPieces[Board.ActivePiece.x, Board.ActivePiece.y] = tmp;
                Board.ActivePiece   = _Gp1;
                Board.PlayerCanMove = false;
                GetComponent <AudioSource>().PlayOneShot(moveSound);
                if (Board.Instance.gameStyle == GameStyle.Standard)
                {
                    Board.ActivePiece.x = -1;
                }
            }
            else if (Board.Instance.gameStyle == GameStyle.Standard)
            {
                Board.ActivePiece = _Gp1;
            }
        }
    }
Beispiel #2
0
        /// <inheritdoc/>
        public override void Process(GridBuffer buffer, int channel)
        {
            // Side length of squares around points required for filling
            // Width x Height, IF positions were distributed evenly.
            float sparseness = Mathf.Sqrt(Width * Height / (float)GridPositions.Count);

            if (sparseness > 1)
            {
                sparseness *= c_Multiplier;

                foreach (Vector2Int pGrid in GridPositions)
                {
                    int xGrid = pGrid.x;
                    int yGrid = pGrid.y;

                    float proximity = m_AuxGrid.Read(0, xGrid, yGrid);
                    // Get matching kernel size for current proximity and point sparseness.
                    var kernel = m_Kernels[Mathf.Min(Mathf.RoundToInt(sparseness * proximity), c_MaxRadius - 1)];

                    float bufferValue = buffer.Read(channel, xGrid, yGrid);

                    foreach (var pKernel in kernel)
                    {
                        int xDilate = xGrid + pKernel.x;
                        int yDilate = yGrid + pKernel.y;

                        // TryRead -> Dilation area might go beyond grid size.
                        if (m_AuxGrid.TryRead(1, xDilate, yDilate, out float kernelValue))
                        {
                            // Occlusion, 3D specific:
                            // Write maximum kernel value if already set.
                            m_AuxGrid.Write(1, xDilate, yDilate, Mathf.Max(pKernel.value, kernelValue));
                            // Write maximum buffer value if already set.
                            m_AuxGrid.Write(2, xDilate, yDilate, Mathf.Max(m_AuxGrid.Read(2, xDilate, yDilate), bufferValue));
                            Expand(xDilate, yDilate);
                        }
                    }
                }

                // Expanded area.
                for (int x = m_xMin; x <= m_xMax; x++)
                {
                    for (int y = m_yMin; y <= m_yMax; y++)
                    {
                        if (m_AuxGrid.Read(1, x, y) > c_Threshold)
                        {
                            // Copy back dilated buffer values.
                            buffer.Write(channel, x, y, m_AuxGrid.Read(2, x, y));
                            // Store for later Write(buffer, channel, value) call.
                            GridPositions.Add(new Vector2Int(x, y));
                        }
                    }
                }
            }
            // else: keep original positions, they're dense enough.
        }
    void OnMouseDrag()
    {
        if ((!Board.PlayerCanMove) || (Board.Instance.gameStyle != GameStyle.Standard) ||
            currentStrenght != TileType.Normal)
        {
            return;
        }
        dragDelay += Time.deltaTime;
        if (dragDelay < 0.2f)
        {
            return;
        }
        dragDelay    = 0f;
        prevPoint    = currentPoint;
        currentPoint = Input.mousePosition;
        _Gp          = GridPositions.GetGridPosition(new Vector2(myTransform.position.x, myTransform.position.y));

        Vector3 dir = currentPoint - prevPoint;

        if (dir.x < -FLOAT_DragDetection)
        {
            if ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x - 1, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchX(_Gp.x - 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x - 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x - 1, _Gp.y, true)))
            {
                MoveTo(_Gp.x - 1, _Gp.y);
                Board.PlayingPieces[_Gp.x - 1, _Gp.y].pieceScript.MoveTo(_Gp.x, _Gp.y);

                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x - 1, _Gp.y];
                Board.PlayingPieces[_Gp.x - 1, _Gp.y] = tmp;

                Board.PlayerCanMove = false;
                //GetComponent<AudioSource>().PlayOneShot(moveSound);

                dragDelay = 0f;
                return;
            }
        }
        if (dir.x > FLOAT_DragDetection)
        {
            if ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x + 1, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchX(_Gp.x + 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x + 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x + 1, _Gp.y, true)))
            {
                MoveTo(_Gp.x + 1, _Gp.y);
                Board.PlayingPieces[_Gp.x + 1, _Gp.y].pieceScript.MoveTo(_Gp.x, _Gp.y);

                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x + 1, _Gp.y];
                Board.PlayingPieces[_Gp.x + 1, _Gp.y] = tmp;

                Board.PlayerCanMove = false;
                //GetComponent<AudioSource>().PlayOneShot(moveSound);

                dragDelay = 0f;
                return;
            }
        }

        if (dir.y > FLOAT_DragDetection)
        {
            if ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x, _Gp.y - 1, true)) ||
                (Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y - 1, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y - 1, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x, _Gp.y - 1, true)))
            {
                MoveTo(_Gp.x, _Gp.y - 1);
                Board.PlayingPieces[_Gp.x, _Gp.y - 1].pieceScript.MoveTo(_Gp.x, _Gp.y);

                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x, _Gp.y - 1];
                Board.PlayingPieces[_Gp.x, _Gp.y - 1] = tmp;

                Board.PlayerCanMove = false;
                //GetComponent<AudioSource>().PlayOneShot(moveSound);

                dragDelay = 0f;
                return;
            }
        }

        if (dir.y < -FLOAT_DragDetection)
        {
            if ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x, _Gp.y + 1, true)) ||
                (Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y + 1, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y + 1, _Gp.x, _Gp.y, true)) ||
                (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x, _Gp.y + 1, true)))
            {
                MoveTo(_Gp.x, _Gp.y + 1);
                Board.PlayingPieces[_Gp.x, _Gp.y + 1].pieceScript.MoveTo(_Gp.x, _Gp.y);

                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x, _Gp.y + 1];
                Board.PlayingPieces[_Gp.x, _Gp.y + 1] = tmp;

                Board.PlayerCanMove = false;
                //GetComponent<AudioSource>().PlayOneShot(moveSound);

                dragDelay = 0f;
                return;
            }
        }
    }
 public void MoveTo(int x, int y, float z)
 {
     moving      = true;
     destination = new Vector3(GridPositions.GetVector(x, y).x, GridPositions.GetVector(x, y).y, z);
 }
 public void MoveTo(int x, int y)
 {
     moving      = true;
     destination = new Vector3(GridPositions.GetVector(x, y).x, GridPositions.GetVector(x, y).y, myTransform.position.z);
 }
Beispiel #6
0
        /// <inheritdoc/>
        public override void Process(GridBuffer buffer, int channel)
        {
            int xCenter = (m_xMin + m_xMax) / 2;
            int yCenter = (m_yMin + m_yMax) / 2;

            float tmpValue = 0;

            for (int x = m_xMin; x <= xCenter; x++)
            {
                int xLeft = Mathf.Max(m_xMin, x - 1);

                for (int y = m_yMin; y <= yCenter; y++)
                {
                    float bufferValue = buffer.Read(channel, x, y);

                    if (bufferValue == 0)
                    {
                        int yTop = Mathf.Max(m_yMin, y - 1);

                        bufferValue = Mathf.Max(
                            buffer.Read(channel, xLeft, y),
                            buffer.Read(channel, x, yTop),
                            buffer.Read(channel, xLeft, yTop));

                        if (bufferValue > 0)
                        {
                            buffer.Write(channel, x, y, bufferValue);
                            tmpValue = bufferValue;
                            // Store for later Write(buffer, channel, value) call.
                            GridPositions.Add(new Vector2Int(x, y));
                        }
                    }
                    else
                    {
                        // Occlusion, 3D specific:
                        // Write maximum buffer value if already set.
                        buffer.Write(channel, x, y, Mathf.Max(tmpValue, bufferValue));
                    }
                }
            }

            tmpValue = 0;

            for (int x = m_xMax; x > xCenter; x--)
            {
                int xRight = Mathf.Min(m_xMax, x + 1);

                for (int y = m_yMin; y <= yCenter; y++)
                {
                    float bufferValue = buffer.Read(channel, x, y);

                    if (bufferValue == 0)
                    {
                        int yTop = Mathf.Max(m_yMin, y - 1);

                        bufferValue = Mathf.Max(
                            buffer.Read(channel, xRight, y),
                            buffer.Read(channel, x, yTop),
                            buffer.Read(channel, xRight, yTop));

                        if (bufferValue > 0)
                        {
                            buffer.Write(channel, x, y, bufferValue);
                            tmpValue = bufferValue;
                            // Store for later Write(buffer, channel, value) call.
                            GridPositions.Add(new Vector2Int(x, y));
                        }
                    }
                    else
                    {
                        // Occlusion, 3D specific:
                        // Write maximum buffer value if already set.
                        buffer.Write(channel, x, y, Mathf.Max(tmpValue, bufferValue));
                    }
                }
            }

            tmpValue = 0;

            for (int x = m_xMin; x <= xCenter; x++)
            {
                int xLeft = Mathf.Max(m_xMin, x - 1);

                for (int y = m_yMax; y > yCenter; y--)
                {
                    float bufferValue = buffer.Read(channel, x, y);

                    if (bufferValue == 0)
                    {
                        int yBottom = Mathf.Min(m_yMax, y + 1);

                        bufferValue = Mathf.Max(
                            buffer.Read(channel, xLeft, y),
                            buffer.Read(channel, x, yBottom),
                            buffer.Read(channel, xLeft, yBottom));

                        if (bufferValue > 0)
                        {
                            buffer.Write(channel, x, y, bufferValue);
                            tmpValue = bufferValue;
                            // Store for later Write(buffer, channel, value) call.
                            GridPositions.Add(new Vector2Int(x, y));
                        }
                    }
                    else
                    {
                        // Occlusion, 3D specific:
                        // Write maximum buffer value if already set.
                        buffer.Write(channel, x, y, Mathf.Max(tmpValue, bufferValue));
                    }
                }
            }

            tmpValue = 0;

            for (int x = m_xMax; x > xCenter; x--)
            {
                int xRight = Mathf.Min(m_xMax, x + 1);

                for (int y = m_yMax; y > yCenter; y--)
                {
                    float bufferValue = buffer.Read(channel, x, y);

                    if (bufferValue == 0)
                    {
                        int yBottom = Mathf.Min(m_yMax, y + 1);

                        bufferValue = Mathf.Max(
                            buffer.Read(channel, xRight, y),
                            buffer.Read(channel, x, yBottom),
                            buffer.Read(channel, xRight, yBottom));

                        if (bufferValue > 0)
                        {
                            buffer.Write(channel, x, y, bufferValue);
                            tmpValue = bufferValue;
                            // Store for later Write(buffer, channel, value) call.
                            GridPositions.Add(new Vector2Int(x, y));
                        }
                    }
                    else
                    {
                        // Occlusion, 3D specific:
                        // Write maximum buffer value if already set.
                        buffer.Write(channel, x, y, Mathf.Max(tmpValue, bufferValue));
                    }
                }
            }
        }
Beispiel #7
0
    internal void StartBoard()
    {
        PlayingPieces = new PlayingPiece[columns, rows];
        intGrid       = new int[columns, rows];

        gdesc = new int[columns, rows];
        float val = Mathf.Max((float)(columns), (float)(rows));

        if (!fillOnx)
        {
            step          = (Mathf.Abs(leftMark.transform.position.x) + Mathf.Abs(RightMark.transform.position.x)) / val;
            halfStep      = step / 2.0f;
            startPosition = new Vector3(leftMark.transform.position.x + halfStep, leftMark.transform.position.y - halfStep, zTilePosition);
        }
        else
        {
            Vector3 left  = Camera.main.ScreenToWorldPoint(new Vector3(0f, 0f, Camera.main.transform.position.z));
            Vector3 right = Camera.main.ScreenToWorldPoint(new Vector3(Mathf.Min((float)Screen.width, (float)Screen.height), 0f, Camera.main.transform.position.z));
            step          = (Mathf.Abs(left.x) + Mathf.Abs(right.x)) / val;
            halfStep      = step / 2.0f;
            startPosition = new Vector3(-(Mathf.Abs(left.x)) + halfStep, left.y - halfStep, zTilePosition);
        }

        float tileScale = (step * val) / (tile.GetComponent <Renderer>().bounds.size.x *val);

        if (!CentreOnx)
        {
            Vector3 realRight = Camera.main.ScreenToWorldPoint(new Vector3((float)Screen.width, 0f, Camera.main.transform.position.z));
            startPosition.x += Mathf.Abs(Mathf.Abs(realRight.x * 2f) - (step * columns)) / 2f;
        }

        generalScale = new Vector3(tileScale, tileScale, 1f);
        GridPositions.Init();

        //TextAsset TxTFile = (TextAsset)Resources.Load
        for (int y = 0; y < rows; y++)
        {
            for (int x = 0; x < columns; x++)
            {
                gdesc[x, y] = new int();
                if (DifficultyManagement.currentDifficulty < Difficulty.Four || x == 0 || x == columns - 1 || y == 0 || y == rows - 1)
                {
                    gdesc[x, y] = 1;
                }
                else
                {
                    if (DifficultyManagement.currentDifficulty >= Difficulty.Four && x > 0 && x < columns - 1 && y > 0 && y < rows - 1)
                    {
                        int tmp = Random.Range(1, 6);
                        gdesc[x, y] = 1 + tmp / 5;
                    }
                }
            }
        }
        for (int y = 0; y < rows; y++)
        {
            for (int x = 0; x < columns; x++)
            {
                float xp, yp = 0f;
                if (gdesc[x, y] != 0)
                {
                    xp = startPosition.x + (x * step);
                    yp = startPosition.y - (y * step);
                    GridPositions.SetPosition(x, y, xp, yp);
                    if (gdesc[x, y] != 99)
                    {
                        bool again = false;
                        do
                        {
                            int t = Random.Range(0, maxPieces);
                            int title;
                            if (DifficultyManagement.currentDifficulty < Difficulty.Three)
                            {
                                title = Random.Range(0, (int)DifficultyManagement.currentDifficulty + 1);
                            }
                            else
                            {
                                title = Random.Range(0, 4);
                            }
                            switch (gdesc[x, y])
                            {
                            case 1:
                                GetPiecesToUse(title);
                                PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(xp, yp, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                break;

                            case 2:
                                GetStrongPiecesToUse(title);
                                PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseStrong[t], new Vector3(xp, yp, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                break;
                            }

                            if (CheckTileMatchX(x, y, true) || CheckTileMatchY(x, y, true))
                            {
                                DestroyImmediate(PlayingPieces[x, y].Piece);
                                PlayingPieces[x, y] = null;
                                again = true;
                            }
                            else
                            {
                                again = false;
                            }
                        } while (again);
                        PlayingPieces[x, y].pieceScript.currentStrenght = (TileType)gdesc[x, y];
                        //PlayingPieces[x, y].pieceScript.MoveTo(x, y, zPiecePosition);
                        //PlayingPieces[x, y].Piece.transform.localScale = generalScale;
                    }
                }
            }
        }
        started = true;
    }
Beispiel #8
0
    void Update()
    {
        //checkMovesTimer += Time.deltaTime;
        if (ScoresManager.CurrentPoints >= WinningScore && started)
        {
            Time.timeScale = 0;
            GameOverText.GetComponent <Text>().text = "You Win!!";
            GameOverText.SetActive(true);
            started = false;
        }
        if (TimeOut && started)
        {
            Time.timeScale = 0;
            GameOverText.GetComponent <Text>().text = "Game Over";
            GameOverText.SetActive(true);
            started = false;
        }
        gameTimer += Time.deltaTime;
        RestTime  -= Time.deltaTime;
        if (RestTime <= 0)
        {
            TimeOut = true;
        }


        if (started)
        {
            _MovingPieces = false;
            for (int y = 0; y < rows; y++)
            {
                for (int x = 0; x < columns; x++)
                {
                    if (PlayingPieces[x, y] != null && PlayingPieces[x, y].Moving)
                    {
                        _MovingPieces = true;
                        y             = rows;
                        break;
                    }
                }
            }
            if (destroyed && !_MovingPieces)
            {
                PlayerCanMove = false;
                destroyed     = false;
                for (int x = 0; x < columns; x++)
                {
                    SlideDown(x, rows - 1);
                }
                NewPieces();
                PlayerCanMove = true;
            }
            if (!_MovingPieces && !destroyed)
            {
                PlayerCanMove = false;
                for (int y = 0; y < rows; y++)
                {
                    for (int x = 0; x < columns; x++)
                    {
                        CheckTileMatchX(x, y, false);
                        CheckTileMatchY(x, y, false);
                    }
                }
                //deal with coins
                int specialCount = 0;
                for (int y = 0; y < rows; y++)
                {
                    for (int x = 0; x < columns; x++)
                    {
                        if (PlayingPieces[x, y] != null && PlayingPieces[x, y].Selected && PlayingPieces[x, y].Piece != null)
                        {
                            //deal with coins
                            //todo
                            _CurrentPosition = GridPositions.GetVector(x, y);
                            switch (PlayingPieces[x, y].pieceScript.currentStrenght)
                            {
                            case TileType.Normal:
                                Destroy(PlayingPieces[x, y].Piece);
                                PlayingPieces[x, y].Piece    = null;
                                PlayingPieces[x, y].Selected = false;
                                PlayingPieces[x, y]          = null;
                                gdesc[x, y] = (int)TileType.Done;
                                ScoresManager.AddPoints(PointsNormal);
                                RestTime += timeToAdd;
                                break;

                            case TileType.Strong:
                                string name = PlayingPieces[x, y].Piece.GetComponent <TextMesh>().text.ToString();
                                Destroy(PlayingPieces[x, y].Piece);
                                GameObject tmp = PieceNormal[0];
                                tmp.GetComponent <TextMesh>().text = name;
                                PlayingPieces[x, y].Piece          = Instantiate(tmp, new Vector3(_CurrentPosition.x, _CurrentPosition.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject;
                                PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                                PlayingPieces[x, y].Selected = false;
                                gdesc[x, y] = (int)TileType.Normal;
                                ScoresManager.AddPoints(PointsNormal);
                                RestTime += timeToAdd;
                                break;
                            }
                            //audio.PlayOneShot(destroyPiece);
                            destroyed = true;
                        }
                    }
                }
                PlayerCanMove = true;
            }
        }
    }
Beispiel #9
0
 private void NewPieces()
 {
     for (int x = 0; x < columns; x++)
     {
         for (int y = 0; y < rows; y++)
         {
             if (gdesc[x, y] != (int)TileType.NoTile && PlayingPieces[x, y] == null)
             {
                 int     chance = Random.Range(0, 7);
                 Vector2 v0     = GridPositions.GetVector(x, y);
                 bool    again  = false;
                 do
                 {
                     int t = Random.Range(0, maxPieces);
                     int title;
                     if (DifficultyManagement.currentDifficulty < Difficulty.Three)
                     {
                         title = Random.Range(0, (int)DifficultyManagement.currentDifficulty + 1);
                     }
                     else
                     {
                         title = Random.Range(0, 4);
                     }
                     if (!newPieceFromTop)
                     {
                         if (DifficultyManagement.currentDifficulty < Difficulty.Five)
                         {
                             GetPiecesToUse(title);
                             PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                             PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                         }
                         else
                         {
                             if (DifficultyManagement.currentDifficulty >= Difficulty.Five)
                             {
                                 int tmp = Random.Range(1, 9);
                                 if (tmp < 8)
                                 {
                                     GetPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                                 }
                                 else
                                 {
                                     GetStrongPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseStrong[t], new Vector3(v0.x, v0.y, zPiecePosition - Random.Range(20f, 30f)), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Strong;
                                 }
                             }
                         }
                     }
                     else
                     {
                         if (DifficultyManagement.currentDifficulty < Difficulty.Five)
                         {
                             GetPiecesToUse(title);
                             PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y + Random.Range(20f, 30f), zPiecePosition - 25f), Quaternion.identity) as GameObject, (PieceColor)title);
                             PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                         }
                         else
                         {
                             if (DifficultyManagement.currentDifficulty >= Difficulty.Five)
                             {
                                 int tmp = Random.Range(1, 9);
                                 if (tmp < 8)
                                 {
                                     GetPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseNormal[t], new Vector3(v0.x, v0.y + Random.Range(20f, 30f), zPiecePosition - 25f), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Normal;
                                 }
                                 else
                                 {
                                     GetStrongPiecesToUse(title);
                                     PlayingPieces[x, y] = new PlayingPiece(Instantiate(piecesToUseStrong[t], new Vector3(v0.x, v0.y + Random.Range(20f, 30f), zPiecePosition - 25f), Quaternion.identity) as GameObject, (PieceColor)title);
                                     PlayingPieces[x, y].pieceScript.currentStrenght = TileType.Strong;
                                 }
                             }
                         }
                     }
                     if (CheckTileMatchX(x, y, true) || CheckTileMatchY(x, y, true))
                     {
                         DestroyImmediate(PlayingPieces[x, y].Piece);
                         PlayingPieces[x, y] = null;
                         again = true;
                     }
                     else
                     {
                         again = false;
                     }
                 } while (again);
                 //audio.PlayOneShot(newPiece);
                 PlayingPieces[x, y].pieceScript.MoveTo(x, y, zPiecePosition - 25f);
                 PlayingPieces[x, y].Selected = false;
             }
             else if (gdesc[x, y] != (int)TileType.NoTile && PlayingPieces[x, y] != null && PlayingPieces[x, y].pieceScript.currentStrenght != TileType.Normal)
             {
                 break;
             }
         }
     }
 }
Beispiel #10
0
    void OnMouseDrag()
    {
        if (
            (!Board.PlayerCanMove || (Board.Instance.gameStyle != GameStyle.Standard)) ||
            currentStrenght == TileType.BlockedTile ||
            currentStrenght == TileType.TodoExtraStrong ||
            currentStrenght == TileType.TodoStrong ||
            currentStrenght == TileType.TodoSuperStrong
            )
        {
            return;
        }
        dragDelay += Time.deltaTime;
        if (dragDelay < 0.2f)
        {
            return;
        }
        dragDelay    = 0;
        prevPoint    = currentPoint;
        currentPoint = Input.mousePosition;
        _Gp          = GridPositions.GetGridPosition(new Vector2(myTransform.position.x, myTransform.position.y));
        Vector3 dir = currentPoint - prevPoint;

        if (dir.x < -FLOAT_DragDetection)
        {
            if (
                (!Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x - 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchX(_Gp.x - 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x - 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x - 1, _Gp.y, _Gp.x, _Gp.y, true))
                 )) ||
                (Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX4(_Gp.x, _Gp.y, _Gp.x - 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchX4(_Gp.x - 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x, _Gp.y, _Gp.x - 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x - 1, _Gp.y, _Gp.x, _Gp.y, true))
                 ))
                )
            {
                MoveTo(_Gp.x - 1, _Gp.y);
                Board.PlayingPieces[_Gp.x - 1, _Gp.y].pieceScript.MoveTo(_Gp.x, _Gp.y);
                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x - 1, _Gp.y];
                Board.PlayingPieces[_Gp.x - 1, _Gp.y] = tmp;
                Board.ActivePiece.x = -1;
                Board.PlayerCanMove = false;
                GetComponent <AudioSource>().PlayOneShot(moveSound);
                mouseClick = false;
                mouseDown  = false;
                dragDelay  = 0f;
                return;
            }
        }
        if (dir.x > FLOAT_DragDetection)
        {
            if (
                (!Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x + 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchX(_Gp.x + 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x + 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x + 1, _Gp.y, _Gp.x, _Gp.y, true))
                 )) ||
                (Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX4(_Gp.x, _Gp.y, _Gp.x + 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchX4(_Gp.x + 1, _Gp.y, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x, _Gp.y, _Gp.x + 1, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x + 1, _Gp.y, _Gp.x, _Gp.y, true))
                 ))
                )
            {
                MoveTo(_Gp.x + 1, _Gp.y);
                Board.PlayingPieces[_Gp.x + 1, _Gp.y].pieceScript.MoveTo(_Gp.x, _Gp.y);
                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x + 1, _Gp.y];
                Board.PlayingPieces[_Gp.x + 1, _Gp.y] = tmp;
                Board.ActivePiece.x = -1;
                Board.PlayerCanMove = false;
                GetComponent <AudioSource>().PlayOneShot(moveSound);
                dragDelay  = 0f;
                mouseClick = false;
                mouseDown  = false;
                return;
            }
        }
        if (dir.y > FLOAT_DragDetection)
        {
            if (
                (!Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x, _Gp.y - 1, true)) ||
                  (Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y - 1, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x, _Gp.y - 1, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y - 1, _Gp.x, _Gp.y, true))
                 )) ||
                (Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX4(_Gp.x, _Gp.y, _Gp.x, _Gp.y - 1, true)) ||
                  (Board.Instance.CheckTileMatchX4(_Gp.x, _Gp.y - 1, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x, _Gp.y, _Gp.x, _Gp.y - 1, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x, _Gp.y - 1, _Gp.x, _Gp.y, true))
                 ))
                )
            {
                MoveTo(_Gp.x, _Gp.y - 1);
                Board.PlayingPieces[_Gp.x, _Gp.y - 1].pieceScript.MoveTo(_Gp.x, _Gp.y);
                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x, _Gp.y - 1];
                Board.PlayingPieces[_Gp.x, _Gp.y - 1] = tmp;
                Board.ActivePiece.x = -1;
                Board.PlayerCanMove = false;
                GetComponent <AudioSource>().PlayOneShot(moveSound);
                dragDelay  = 0f;
                mouseClick = false;
                mouseDown  = false;
                return;
            }
        }
        if (dir.y < -FLOAT_DragDetection)
        {
            if (
                (!Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y, _Gp.x, _Gp.y + 1, true)) ||
                  (Board.Instance.CheckTileMatchX(_Gp.x, _Gp.y + 1, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y, _Gp.x, _Gp.y + 1, true)) ||
                  (Board.Instance.CheckTileMatchY(_Gp.x, _Gp.y + 1, _Gp.x, _Gp.y, true))
                 )) ||
                (Board.Instance.isMatch4 &&
                 ((Board.Instance.CheckTileMatchX4(_Gp.x, _Gp.y, _Gp.x, _Gp.y + 1, true)) ||
                  (Board.Instance.CheckTileMatchX4(_Gp.x, _Gp.y + 1, _Gp.x, _Gp.y, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x, _Gp.y, _Gp.x, _Gp.y + 1, true)) ||
                  (Board.Instance.CheckTileMatchY4(_Gp.x, _Gp.y + 1, _Gp.x, _Gp.y, true))
                 ))
                )
            {
                MoveTo(_Gp.x, _Gp.y + 1);
                Board.PlayingPieces[_Gp.x, _Gp.y + 1].pieceScript.MoveTo(_Gp.x, _Gp.y);
                PlayingPiece tmp = Board.PlayingPieces[_Gp.x, _Gp.y];
                Board.PlayingPieces[_Gp.x, _Gp.y]     = Board.PlayingPieces[_Gp.x, _Gp.y + 1];
                Board.PlayingPieces[_Gp.x, _Gp.y + 1] = tmp;
                Board.ActivePiece.x = -1;
                Board.PlayerCanMove = false;
                GetComponent <AudioSource>().PlayOneShot(moveSound);
                dragDelay  = 0f;
                mouseClick = false;
                mouseDown  = false;
                return;
            }
        }
    }
        /// <inheritdoc/>
        public override void Process(GridBuffer buffer, int channel)
        {
            // Side length of squares around points required for filling
            // Width x Height, IF positions were distributed evenly.
            float sparseness = Mathf.Sqrt(Width * Height / (float)GridPositions.Count);

            if (sparseness > 1)
            {
                // Make downsample area a bit larger than
                // sparseness value in order to prevent gaps.
                int size = Mathf.RoundToInt(sparseness) + 2; // TBD pad

                // Bottom/left offset.
                int xOffset = m_xMin - (size - Width % size) / 2;
                int yOffset = m_yMin - (size - Height % size) / 2;

                int nx = 0, ny = 0;
                foreach (Vector2Int point in GridPositions)
                {
                    // Downsampling: grid pos -> sample pos.
                    int xSample = (point.x - xOffset) / size;
                    int ySample = (point.y - yOffset) / size;

                    nx = Mathf.Max(nx, xSample);
                    ny = Mathf.Max(ny, ySample);

                    m_Samples[xSample, ySample] = Mathf.Max(
                        m_Samples[xSample, ySample], buffer.Read(channel, point));
                }

                // Replace grid points with squares (size x size).
                GridPositions.Clear();

                for (int xSample = 0; xSample <= nx; xSample++)
                {
                    for (int ySample = 0; ySample <= ny; ySample++)
                    {
                        float sampleValue = m_Samples[xSample, ySample];

                        if (sampleValue > 0)
                        {
                            // Upscaling: sample pos -> grid pos.
                            int xGrid = xOffset + xSample * size;
                            int yGrid = yOffset + ySample * size;

                            for (int x = 0; x < size; x++)
                            {
                                for (int y = 0; y < size; y++)
                                {
                                    Vector2Int gridPos = new Vector2Int(xGrid + x, yGrid + y);
                                    // TryRead -> Square might go beyond grid size.
                                    if (buffer.TryRead(channel, gridPos, out float bufferValue))
                                    {
                                        // Occlusion, 3D specific:
                                        // Write maximum buffer value if already set.
                                        buffer.Write(channel, gridPos, Mathf.Max(bufferValue, sampleValue));
                                        // Store for later Write(buffer, channel, value) call.
                                        GridPositions.Add(gridPos);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // else: keep original positions, they're dense enough.
        }