Пример #1
0
    private void LandShape()
    {
        _activeShape.MoveUp();
        _backgroundGrid.StoreShapeInGrid(_activeShape);

        PlaySound(_audioManager.dropSound, 0.75f);

        _activeShape = _spawner.SpawnShape();

        _timeNextLeftKey  = Time.time;
        _timeNextRightKey = Time.time;
        _timeNextDownKey  = Time.time;
        _timeNextDownKey  = Time.time;

        _backgroundGrid.StartCoroutine("ClearAllRows");

        if (_backgroundGrid.completedRows > 0)
        {
            _scoreController.ScoreLines(_backgroundGrid.completedRows);

            if (_scoreController.isLevelUp)
            {
                PlaySound(_audioManager.levelUpSound, 0.35f);
                _dropTimeInterval = Mathf.Clamp(_timeInterval - (((float)_scoreController._level - 1) * 0.05f), 0.05f, 1f);
            }
            else
            {
                PlaySound(_audioManager.clearRowSound, 0.25f);
            }

            //PlaySound(_audioManager.clearRowSound, 0.15f);
        }
    }
Пример #2
0
    private void FillQueue()
    {
        if (!_queuedShape)
        {
            _queuedShape = Instantiate(GetRandomShape(), transform.position, Quaternion.identity);

            _queuedShape.transform.position   = queuedForms.position + _queuedShape._queuedOffset;
            _queuedShape.transform.localScale = new Vector3(_queueScale, _queueScale, _queueScale);
        }
    }
Пример #3
0
 public bool IsOverLimit(BrickTetris_BrickShape shape)
 {
     foreach (Transform child in shape.transform)
     {
         if (child.transform.position.y >= (height - header))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
    // Start is called before the first frame update
    void Start()
    {
        _timeNextLeftKey   = Time.time + _timeRepeatRateLeftKey;
        _timeNextRightKey  = Time.time + _timeRepeatRateRightKey;
        _timeNextDownKey   = Time.time + _timeRepeatRateDownKey;
        _timeNextRotateKey = Time.time + _timeRepeatRateRotateKey;

        _dropTimeInterval = _timeInterval;

        _backgroundGrid = FindObjectOfType <BrickTetris_BackgroundGrid>();
        if (!_backgroundGrid)
        {
            Debug.Log("not assign object");
        }

        _spawner = FindObjectOfType <BrickTetris_Spawner>();
        if (!_spawner)
        {
            Debug.Log("not assign object");
        }
        else
        {
            _spawner.transform.position = BrickTetris_Vectorf.Round(_spawner.transform.position);

            if (!_activeShape)
            {
                _activeShape = _spawner.SpawnShape();
            }
        }

        _audioManager = FindObjectOfType <BrickTetris_AudioManager>();
        if (!_audioManager)
        {
            Debug.Log("not assign object");
        }

        _scoreController = FindObjectOfType <BrickTetris_ScoreController>();
        if (!_scoreController)
        {
            Debug.Log("not assign object");
        }

        _animator = GetComponent <Animator>();
        if (!_animator)
        {
            Debug.Log("not assign object");
        }

        if (_pausePanel)
        {
            _pausePanel.SetActive(false);
        }
    }
Пример #5
0
    public void StoreShapeInGrid(BrickTetris_BrickShape shape)
    {
        if (shape == null)
        {
            return;
        }

        foreach (Transform child in shape.transform)
        {
            Vector2 position = BrickTetris_Vectorf.Round(child.position);
            _grid[(int)position.x, (int)position.y] = child;
        }
    }
Пример #6
0
    private BrickTetris_BrickShape GetQueuedShape()
    {
        BrickTetris_BrickShape firstShape = null;

        if (_queuedShape)
        {
            firstShape = _queuedShape;
        }

        _queuedShape = null;

        FillQueue();

        return(firstShape);
    }
Пример #7
0
    public bool IsValidPosition(BrickTetris_BrickShape shape)
    {
        foreach (Transform child in shape.transform)
        {
            Vector2 position = BrickTetris_Vectorf.Round(child.position);

            if (!IsInGrid((int)position.x, (int)position.y))
            {
                return(false);
            }

            if (IsValidOccupied((int)position.x, (int)position.y, shape))
            {
                return(false);
            }
        }
        return(true);
    }
Пример #8
0
    public BrickTetris_BrickShape SpawnShape()
    {
        BrickTetris_BrickShape shape = null;

        shape = GetQueuedShape();

        shape.transform.position   = transform.position;
        shape.transform.localScale = Vector3.one;

        if (shape)
        {
            return(shape);
        }
        else
        {
            Debug.Log("invalid shape");
            return(null);
        }
    }
Пример #9
0
    private void InitQueue()
    {
        _queuedShape = null;

        FillQueue();
    }
Пример #10
0
 private bool IsValidOccupied(int x, int y, BrickTetris_BrickShape shape)
 {
     return(_grid[x, y] != null && _grid[x, y].parent != shape.transform);
 }