예제 #1
0
    private IEnumerator AnimateBulletPath(Vector3[] nodes, int iterator)
    {
        while (iterator + 1 < nodes.Length)
        {
            var difference = nodes[iterator + 1] - nodes[iterator];
            difference = difference.normalized;

            GhostCircle.transform.position += difference * BulletSpeed;

            if (GhostCircle.transform.position.y > nodes[iterator + 1].y)
            {
                GhostCircle.transform.position = nodes[iterator + 1];
                iterator++;
            }

            yield return(0);
        }

        SelectedGridSquare.SetOccupied(CurrentSquare.Value);


        GridManager.OnGridChanged(SelectedGridSquare);

        ReloadGun();
    }
예제 #2
0
    private void ReloadGun()
    {
        CanFire = true;
        GhostSquare.UnOccupy();

        CurrentSquare.SetOccupied(NextSquare.Value);

        //gun values are minus the highest board value.
        var value = NextSquare.ValueController.GridValues[Random.Range(0, NextSquare.ValueController.GridValues.Count - 1)];

        NextSquare.SetOccupied(value);

        AnimateDummyReload();
    }
예제 #3
0
    private void CheckCombiningCells(GridSquare cell, int iterator)
    {
        //once we have all the surronding same value cells, figue out what the new value is, and see if there is a cell with that value nearby to combine to
        if (HitCells.Count < 2)
        {
            return;
        }

        cell.UnOccupy();

        GridSquare CombineCell = HitCells[1];
        bool       hasMatched  = false;

        int newValue = cell.Value * (int)Mathf.Pow(2, HitCells.Count - 1);

        //foreach cell in the hit cells, check the surronding cels of each one and see if there's the new value adjacent to them
        foreach (GridSquare square in HitCells)
        {
            var SurrondingCells = CheckSurrondingCells(square);
            foreach (GridSquare adjacent in SurrondingCells)
            {
                if (adjacent.Value == newValue && !hasMatched)
                {
                    //found a match and will combine to that one after this is over.
                    CombineCell = square;
                    hasMatched  = true;
                    break;
                }

                square.UnOccupy();
            }
        }

        if (!hasMatched)
        {
            CombineCell = HitCells[HitCells.Count - 1];
        }

        //at that cell, occupy with the new value.
        CombineCell.SetOccupied(newValue);

        //animate the combination
        foreach (GridSquare square in HitCells)
        {
            if (square == CombineCell)
            {
                continue;
            }

            var obj = Instantiate(FallSquarePrefab);
            obj.transform.position = square.transform.position;
            var script = obj.GetComponent <GridSquare>();
            script.SetOccupied(square.Value);
            script.CombineGridSquare(CombineCell.transform.position);
        }

        GameManager.OnScoreChange(newValue, HitCells.Count, CombineCell.transform.position);
        PFXPooler.PlayPFX(CombineCell.transform.position);
        SFXPooler.PlaySFX(newValue);

        //TODO: if that cell now has a value > 2048, explode

        //once done check call GridChanging at the new cell.
        GridChanging(CombineCell, iterator + 1);
    }