Example #1
0
    public void AddPieceToList(APiece piece)
    {
        if (SelectedPieces.Contains(piece))
        {
            int indexOfDuplicate = SelectedPieces.IndexOf(piece);
            SelectedPieces.RemoveRange(indexOfDuplicate + 1, SelectedPieces.Count - indexOfDuplicate - 1);
        }
        else
        {
            if (SelectedPieces.Count >= 1)
            {
                PieceData previousPieceData = SelectedPieces[0].GetComponent <PieceData>();
                PieceData currentPieceData  = piece.GetComponent <PieceData>();

                if (previousPieceData.Color == currentPieceData.Color && MyUtils.IsTileAdjacent(SelectedPieces[SelectedPieces.Count - 1].ParentTile, piece.ParentTile) && previousPieceData.Type != EPieceType.Bomb)
                {
                    SelectedPieces.Add(piece);
                }
            }
            else
            {
                SelectedPieces.Add(piece);
            }
        }

        UpdateHighlight();
    }
Example #2
0
 // Sets the velocity of this piece to the velocity of the one underneath
 // so they fall together
 private void MatchTargetPieceVelocity(APiece targetPiece)
 {
     if (targetPiece && targetPiece.IsMoving)
     {
         Velocity = targetPiece.Velocity;
     }
 }
Example #3
0
    public void CreateBomb(int x, int y)
    {
        Tile tile = BoardData.GetTileAt(x, y);

        GameObject bomb = PiecePooler.GetObjectOfType("Piece_Bomb");

        bomb.transform.position = tile.transform.position;
        bomb.SetActive(true);
        APiece piece = bomb.GetComponent <APiece>();

        tile.Piece = piece;
    }
Example #4
0
    public void CreatePieceAt(int x, int y, int color, float offsetX = 0f, float offsetY = 0f)
    {
        Tile tile = BoardData.GetTileAt(x, y);

        if (tile && tile.Piece == null)
        {
            Transform  tileTransform = tile.transform;
            Vector3    tilePosition  = new Vector3(tileTransform.position.x + offsetX, tileTransform.position.y + offsetY, tileTransform.position.z);
            GameObject obj           = PiecePooler.GetObjectOfType(PiecePrefabs[color].name);
            obj.transform.position = tilePosition;
            obj.SetActive(true);
            APiece piece = obj.GetComponent <APiece>();
            tile.Piece = piece;
        }
    }
Example #5
0
    private void MovePiece()
    {
        if (thisTransform.position != ParentTile.thisTransform.position)
        {
            Tile    targetTile  = null;
            APiece  targetPiece = null;
            Vector3 moveVector  = Vector3.zero;

            if (!IsMoving)
            {
                IsMoving = true;
                BoardData.Instance.Moving++;
                Velocity = 0.0f;
            }

            targetTile = ParentTile.GravityTargetTile;

            targetPiece = targetTile ? targetTile.Piece : null;

            MatchTargetPieceVelocity(targetPiece);
            AcceleratePiece();

            FixPiecePosition();

            moveVector              = moveDirection(moveVector);
            moveVector              = moveVector.normalized * Velocity;
            thisTransform.position += moveVector * Time.deltaTime;
        }
        else
        {
            // Rechecks the gravity on the current parent tile as the piece falls
            // Makes the pieces falls smoothly from tile to tile
            ParentTile.GravityHandler();

            if (IsMoving)
            {
                IsMoving = false;
                Velocity = 0;
                BoardData.Instance.Moving--;
            }
        }
    }