Esempio n. 1
0
        void NewGame()
        {
            _state       = State.Normal;
            _scoreCount  = 0;
            _currentBall = null;
            UpdateScore();

            if (gameOverObject)
            {
                gameOverObject.SetActive(false);
            }

            _freeCells.Clear();
            for (int y = 0; y < grid.rowsCount; y++)
            {
                for (int x = 0; x < grid.colsCount; x++)
                {
                    _freeCells.Add(new IntVector2(x, y));
                }
            }

            foreach (var ball in _ballsGrid)
            {
                if (ball)
                {
                    Destroy(ball.gameObject);
                }
            }

            CreateBalls(startBallsCount);
        }
Esempio n. 2
0
 public void Init(GridBall ball)
 {
     if (ball.image)
     {
         ball.image.sprite = sprite;
         ball.image.color  = color;
     }
 }
Esempio n. 3
0
        void BallClick(GridBall ball)
        {
            if (_state != State.Normal || _currentBall == ball)
            {
                return;
            }

            if (_currentBall)
            {
                _currentBall.selected = false;
            }
            _currentBall = ball;
            if (_currentBall)
            {
                _currentBall.selected = true;
            }
        }
Esempio n. 4
0
        IEnumerator MovePathAnimation()
        {
            _state = State.AnimatePath;
            _currentBall.selected = false;

            while (_movePath.Count > 0)
            {
                float   time  = 0;
                Vector3 start = _currentBall.transform.position;
                Vector3 end   = grid.GetCell(_movePath[0].x, _movePath[0].y).transform.position;

                while (time < moveTime)
                {
                    float t = time / moveTime;
                    _currentBall.transform.position = Vector3.Lerp(start, end, t);
                    time += Time.deltaTime;
                    yield return(null);
                }

                _currentBall.transform.position = end;
                _currentBall.position           = _movePath[0];
                _movePath.RemoveAt(0);
            }

            var pos = _currentBall.position;

            _ballsGrid[pos.x, pos.y] = _currentBall;
            _currentBall.selected    = false;
            _currentBall             = null;
            _state = State.Normal;

            if (!RemoveLines())
            {
                NextTurn();
            }
        }