コード例 #1
0
    private void Start()
    {
        var pi         = GetComponent <PlayerInput>();
        var leftAction = pi.actions.FindAction("Left", true);

        leftAction.started   += c => MoveAction(c, isLeft: true);
        leftAction.performed += c => MoveAction(c, isLeft: true);
        var rightAction = pi.actions.FindAction("Right", true);

        rightAction.started   += c => MoveAction(c, isLeft: false);
        rightAction.performed += c => MoveAction(c, isLeft: false);
        var downAction = pi.actions.FindAction("Down", true);

        downAction.performed += _ => _moveDirection = Logic.DropPiece.MoveDirection.Down;
        var rotateAction = pi.actions.FindAction("Rotate", true);

        rotateAction.performed += _ => _moveDirection = Logic.DropPiece.MoveDirection.Rotate;

        /*
         * GetComponentInChildren<ParticleSystem>().enableEmission = false;
         * GetComponentInChildren<ParticleSystem>().GetComponent<Renderer>().sortingLayerName = "PlayfieldHack";*/

        _logic.HoldTime      = holdTime;
        _logic.DownDropRate  = downDropRate;
        _logic.DropRateWhole = dropRateWhole;
        _logic.DropRateSplit = dropRateSplit;
        _logic.Rotated      += this.Rotated;

        _logic.NewColumnOrRow += (sender, args) => _newColumnOrRow = true;
    }
コード例 #2
0
    private void MoveAction(InputAction.CallbackContext context, bool isLeft)
    {
        Debug.Log($"duration: {context.duration} time: {context.time} startTime: {context.startTime}");
        var dir = isLeft ? Logic.DropPiece.MoveDirection.Left : Logic.DropPiece.MoveDirection.Right;

        if (context.interaction is HoldInteraction && context.phase == InputActionPhase.Performed)
        {
            _fastMoveDirection = dir;
        }
        else
        {
            _moveDirection = dir;
        }
    }
コード例 #3
0
    void Update()
    {
        _newColumnOrRow = false;

        var playfield = playfieldManager.Playfield;

        if (_fastMoveDirection != Logic.DropPiece.MoveDirection.None)
        {
            _moveDirection = _fastMoveDirection;
        }
        bool moved = _logic.Update(TimeSpan.FromSeconds(Time.deltaTime), _moveDirection,
                                   (c, r, i) => c >= 0 && c < playfield.NumCellColumns - 1,
                                   (d) => playfieldManager.PlayMoveSnd(),
                                   (p) => p.Row >= playfield.NumCellRows || playfield.GetCell(p).IsOccupied,
                                   playfieldManager.PopulateCell
                                   );

        if (!moved)
        {
            _fastMoveDirection = DropPiece.MoveDirection.None;
        }

        const int numColumns = Logic.DropPiece.NumColumns;
        const int numRows    = Logic.DropPiece.NumRows;

        // show drop piece:
        if (_instantiatePieces)
        {
            var dps = playfieldManager.PopPreview();
            _instantiatePieces  = false;
            _logic.DownDropRate = downDropRate;
            _logic.Reset(new PlayfieldPoint(0, 0), dps);
            if (_pieces == null)
            {
                _pieces = new Tile[numColumns, numRows];
                for (var c = 0; c < numColumns; c++)
                {
                    for (var r = 0; r < numRows; r++)
                    {
                        _pieces[c, r] = new Tile();
                    }
                }
            }
            UpdateVisuals = true;
        }

        // instantiate pieces:
        if (UpdateVisuals)
        {
            DestroyVisuals();
            var level = playfieldManager.Level;

            for (var c = 0; c < numColumns; c++)
            {
                for (var r = 0; r < numRows; r++)
                {
                    var        cell = _logic.Cells[c][r];
                    GameObject tile = null, adornment = null;
                    Transform  pfTransform = null;
                    playfieldManager.GetTileVisuals(cell, out tile, out adornment, out pfTransform);
                    _pieces[c, r].Instantiate(tile, adornment, Vector3.zero, pfTransform, new TileAnimParams(jewelEaseType, jewelHighlightAnimTime));
                }
            }
            UpdateVisuals = false;
        }

        ComputeDropPiecePosition();

        if (_logic.CurrentState == DropPiece.State.Complete)
        {
            /*Vector2 prevPos = playfieldManager.ComputePos(
             *             _logic.Positions[0].Column,
             *             _logic.Positions[0].Row + 2
             *             );
             * GetComponentInChildren<ParticleSystem>().transform.position = new Vector3(prevPos.x, prevPos.y, 0.0f);
             *
             * var ps = GetComponentInChildren<ParticleSystem>();
             * var em = ps.emission;
             * em.enabled = true;
             * ps.Play();
             */

            //StartCoroutine(StopSparks());
            DestroyVisuals();
            _instantiatePieces = true;
        }

        _moveDirection = DropPiece.MoveDirection.None;
    }