Пример #1
0
 /// <summary>
 /// Match the position and rotation (not scale) of the above object to this one.
 /// </summary>
 protected void SnapToSelf(PlayingPiece objAbove)
 {
     // snap position
     // snap rotation
     //      note: cards should be able to be placed upside down, so snap based on shortest path for 180 degrees
     throw new NotImplementedException();
 }
Пример #2
0
        /// <summary>
        ///  Combine the above object with this one if both are copies of each other.
        /// </summary>
        protected override void NotifyReceipientOfPlacement(PlayingPiece objAbove)
        {
            // TODO: add PlayingPiece.GetOriginal
            // TODO: add PlayingPiece.Initialize
            // TODO: add PlayingPiece.Clone

            throw new System.NotImplementedException();
        }
Пример #3
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;
            }
        }
    }
Пример #4
0
 /// <summary>
 /// Add an element to the top of the container.
 /// </summary>
 public void Add(PlayingPiece piece)
 {
     // # Make sure to check if the added piece is already a container.
     // if (piece == Container)
     //      foreach (element in container)
     //          self.add(element)
     // else
     //      push(piece)
     throw new System.NotImplementedException();
 }
Пример #5
0
        /// <summary>
        /// Combine the above object with this one if both are of the same component type.
        /// </summary>
        protected override void NotifyReceipientOfPlacement(PlayingPiece objAbove)
        {
            var self  = GetComponent <PlayingPiece>().GetComponentType();
            var other = objAbove.GetComponentType();

            if (!string.IsNullOrWhiteSpace(self) && !string.IsNullOrWhiteSpace(other) &&
                string.Equals(self, other))
            {
                Debug.Log("Both are GroupableWithComponent");

                throw new NotImplementedException();
            }
        }
Пример #6
0
        /// <summary>
        /// Create a new container from the two elements.
        /// If the first element is already a container, simply add the second element to it instead.
        /// </summary>
        /// <param name="first">First element to add to the container.</param>
        /// <param name="second">Second element to add to the container. Will be above the first element.</param>
        /// <returns>The new container, or the first element if it is already a container.</returns>
        public static Container CreateFrom(PlayingPiece first, PlayingPiece second)
        {
            // TODO: should this method actually return the created container?
            // TODO: Decide whether to deactivate elements or to serialize and destroy them.
            // if (first == Container)
            //      first.Add(second)
            //      return first
            // else
            //      var container = CreateGameObject(Container)
            //      container.Add(first)
            //      container.Add(second)
            //      return container

            throw new System.NotImplementedException();
        }
Пример #7
0
        /// <summary>
        /// Combine the above object with this one if both are the same class.
        /// </summary>
        protected override void NotifyReceipientOfPlacement(PlayingPiece objAbove)
        {
            // TODO: move "GetComponent<PlayingPiece>().GetType();" to Awake() in base class.
            var self  = GetComponent <PlayingPiece>().GetType();
            var other = objAbove.GetType();

            if (self.IsAssignableFrom(other) || other.IsAssignableFrom(self))
            {
                Debug.Log("Both are GroupableWithClass");

                SnapToSelf(objAbove);

                var thisObj = GetComponent <PlayingPiece>();
                Container.CreateFrom(thisObj, objAbove);
            }
        }
Пример #8
0
    private PlayingPiece MakeAPiece()
    {
        Debug.Log("Piece Made");
        PlayingPiece toReturn = GameObject.Instantiate(piecePrefab);

        if (forcedPieces.Count > 0)
        {
            int[,] forcedPiece = forcedPieces[0];
            forcedPieces.RemoveAt(0);
            toReturn.Initialize(this.player, dice, forcedPiece);
        }
        else
        {
            int num       = dice.NextInt(0, pieceSizeBag.Length);
            int pieceSize = pieceSizeBag[num];
            toReturn.Initialize(this.player, dice, pieceArray[pieceSize][dice.NextInt(0, pieceArray[pieceSize].Length)]);
        }

        return(toReturn);
    }
Пример #9
0
    public void ForcePieces(List <int[, ]> forcedPieces)
    {
        this.forcedPieces = forcedPieces;
        PlayingPiece oldPiece1 = currentPiece;
        PlayingPiece oldPiece2 = nextPiece;

        currentPiece = MakeAPiece();
        nextPiece    = MakeAPiece();
        Debug.Log(oldPiece1);
        GameObject.Destroy(oldPiece1.gameObject);
        GameObject.Destroy(oldPiece2.gameObject);

        currentPiece.transform.parent = this.transform;
        currentPiecePosition          = new Vector2Int(1, 1);
        UpdateCurrentPieceTransform();

        nextPiece.transform.parent        = nextPieceHolder;
        nextPiece.transform.localPosition = Vector3.zero;

        prevPieceRotation = currentPieceRotation = 0;
    }
Пример #10
0
    internal void SetSeedAndStart(int randomSeed)
    {
        seeded = randomSeed;

        if (isRecording)
        {
            recorder = new GameRecorder(randomSeed);
        }

        dice = new SeededRandom(randomSeed);

        SetupPieceArray();

        currentPiece = MakeAPiece();

        currentPiece.transform.parent = this.transform;
        UpdateCurrentPieceTransform();

        nextPiece = MakeAPiece();
        nextPiece.transform.parent        = nextPieceHolder;
        nextPiece.transform.localPosition = Vector3.zero;

        SetGridCellTypeStateAndAttendentVFX();


        if (isPlayerOne)
        {
            string dataPath;


            dataPath = Path.Combine(Application.persistentDataPath, MissionManager.instance.player1CharacterSheetPath);
            if (!File.Exists(dataPath))
            {
                player.SaveCharacterToDisk(MissionManager.instance.player1CharacterSheetPath);
            }

            player.SetCharacterSheet(MissionManager.instance.player1CharacterSheetPath);
        }
    }
Пример #11
0
    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;
            }
        }
    }
 protected override void NotifyReceipientOfPlacement(PlayingPiece objAbove)
 {
     // Do nothing.
 }
Пример #13
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;
    }
Пример #14
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;
             }
         }
     }
 }
Пример #15
0
 /// <summary>
 /// Place a card on top of the deck.
 /// </summary>
 public void AddCard(PlayingPiece card)
 {
     cards.Push(card);
     card.gameObject.SetActive(false);
     MatchTransform(card);
 }
Пример #16
0
 /// <summary>
 /// Do something when an object is placed on top of this one.
 /// </summary>
 protected abstract void NotifyReceipientOfPlacement(PlayingPiece objAbove);
Пример #17
0
        protected override void NotifyReceipientOfPlacement(PlayingPiece objAbove)
        {
            Debug.Log("This is GroupableWithAll");

            throw new NotImplementedException();
        }
Пример #18
0
 /// <summary>
 /// Match the position, rotation, and scale of the card to the deck.
 /// </summary>
 private void MatchTransform(PlayingPiece card)
 {
     card.transform.position = transform.position;
     // rotation
     // scale
 }
Пример #19
0
    public void DropPiece()
    {
        //Place the cubes from the piece to the board.
        for (int x = 0; x < 3; x++)
        {
            for (int y = 0; y < 3; y++)
            {
                if (currentPiece.HasBlockAt(x, y))
                {
                    GameCube cube = currentPiece.GetCubeAt(x, y);
                    grid[currentPiecePosition.x + x - 1, currentPiecePosition.y + y - 1] = cube;
                    cube.transform.parent        = this.transform;
                    cube.transform.localPosition = new Vector3(currentPiecePosition.x - numCells.x / 2f + x - 1 + .5f, 0, currentPiecePosition.y - numCells.y / 2f + y - 1 + .5f);
                }
            }
        }

        //Check for squares
        List <GameCube> cubesToExplode = new List <GameCube>();

        int numberOfSquaresMade = 0;

        for (int x = 0; x < numCells.x - 2; x++)
        {
            for (int y = 0; y < numCells.y - 2; y++)
            {
                if (IsCornerOfSquare(x, y))
                {
                    AddCubesFromSquareToList(x, y, cubesToExplode);
                    numberOfSquaresMade++;
                }
            }
        }

        int numberOfParticles = numberOfSquaresMade * 3;

        List <float> delays = new List <float>();

        for (int x = 0; x < numberOfParticles; x++)
        {
            float delay = UnityEngine.Random.Range(0, Mathf.Sqrt(numberOfSquaresMade / 2));
            delays.Add(delay);
        }

        delays.Sort();

        player.StartNewParticleBarrage();

        foreach (float delay in delays)
        {
            if (player.HasRoomForMoreEnergy())
            {
                PowerupEffect pe         = GameObject.Instantiate <PowerupEffect>(powerUpEffect);
                GameCube      sourceCube = cubesToExplode[UnityEngine.Random.Range(0, cubesToExplode.Count)];
                pe.Initialize(sourceCube.transform.position, player.GetTargetOfParticle(PowerupType.ENERGY, 3), delay, PowerupType.ENERGY);
                InvisibleDelayedChargeGiver chargeGiver = GameObject.Instantiate <InvisibleDelayedChargeGiver>(chargeGiverPrefab);
                chargeGiver.target = player;
                chargeGiver.delay  = delay + 1;
                chargeGiver.type   = PowerupType.ENERGY;
                chargeGiver.SetAmountForOneCube(PowerupType.ENERGY);
                chargeGiver.amount /= 3; //(3 particles per square made);
            }
        }

        if (numberOfSquaresMade != 0)
        {
            matchSound.Play();
            if (numberOfSquaresMade >= 2)
            {
                Vector3    centroid       = FindCentroid(cubesToExplode);
                GameObject comboParticles = comboParticleHolder.comboParticles[numberOfSquaresMade].gameObject;
                GameObject go             = GameObject.Instantiate(comboParticles);
                go.transform.position = centroid;
            }
        }
        else
        {
            dropSound.Play();
        }

        //This is where we handle explosions based on tile color.
        for (int x = 0; x < numCells.x; x++)
        {
            for (int y = 0; y < numCells.y; y++)
            {
                if (grid[x, y] != null && cubesToExplode.Contains(grid[x, y]))
                {
                    //A cube that has exploded is on a tile. What kind?
                    switch (cellTypes[x, y])
                    {
                    case CellType.ATTACK:
                        cubeConversionManager.QueueCube(grid[x, y], PowerupType.ATTACK);
                        cubesToExplode.Remove(grid[x, y]);
                        grid[x, y] = null;
                        break;

                    case CellType.SHIELD:
                        cubeConversionManager.QueueCube(grid[x, y], PowerupType.SHIELDS);
                        cubesToExplode.Remove(grid[x, y]);
                        grid[x, y] = null;
                        break;
                    }
                }
            }
        }

        foreach (GameCube cube in cubesToExplode)
        {
            RemoveCubeFromGrid(cube);
            cube.Sink(UnityEngine.Random.Range(0, Mathf.Sqrt(numberOfSquaresMade)));
        }

        Destroy(currentPiece.gameObject);

        currentPiece = nextPiece;
        currentPiece.transform.parent = this.transform;
        currentPiecePosition          = new Vector2Int(1, 1);
        UpdateCurrentPieceTransform();

        nextPiece = MakeAPiece();
        nextPiece.transform.parent        = nextPieceHolder;
        nextPiece.transform.localPosition = Vector3.zero;

        prevPieceRotation = currentPieceRotation = 0;

        //For tutorials; hack in a callback;
        if (MissionManager.triggerCallbacksOnBlockDrop)
        {
            MissionManager.instance.grossCallbackHack.enabled = true;
        }
    }
Пример #20
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;
            }
        }
    }