示例#1
0
文件: Snake.cs 项目: ChayDealer/JSJA
    public void ContinueGame()
    {
        //if (curGameState == GameState.Game || curGameState == GameState.Immun) return;
        if (curGameState == _prevGameState)
        {
            return;
        }

        if (_prevGameState == GameState.Game || _prevGameState == GameState.Immun)
        {
            //StartCoroutine(_move);
            PauseBonusSpawn?.Invoke();
            curGameState = _prevGameState;
        }
        else if (AdsController.AfterRevAddVideo)
        {
            AdsController.AfterRevAddVideo = false;

            //StartCoroutine(_move);
            PauseBonusSpawn?.Invoke();

            c1 = _defaultColor; c2 = immunColors[Random.Range(0, immunColors.Length)];
            _immunTimeStart = Time.time;
            _immunTimeLeft  = _immunTimeMax - (Time.time - _immunTimeStart);
            SetImunTimeText?.Invoke(FormatTime(_immunTimeLeft));
            immunTimeGameObj.SetActive(true);

            curGameState = GameState.Immun;
        }
        else
        {
            curGameState = _prevGameState;
        }

        Time.timeScale = 1.0f;
        ChangeMusicState?.Invoke(true);
    }
示例#2
0
文件: Snake.cs 项目: ChayDealer/JSJA
    private void Update()
    {
        if (curGameState == GameState.Game || curGameState == GameState.Immun)
        {
            if (curGameState == GameState.Immun)
            {
                _immunTimeLeft = _immunTimeMax - (Time.time - _immunTimeStart);
                SetImunTimeText?.Invoke(FormatTime(_immunTimeLeft));

                _headSR.color = Color.Lerp(c1, c2, _colorTimer / _colorChangeTime);
                _colorTimer  += Time.deltaTime;
                ChangeTailColor(c1, c2);

                if (_colorTimer >= _colorChangeTime)
                {
                    c1 = c2;

                    if (_immunTimeLeft <= 2.01f)
                    {
                        c2 = _defaultColor;
                    }
                    else
                    {
                        do
                        {
                            c2 = immunColors[Random.Range(0, immunColors.Length)];
                        } while (c1 == c2);
                    }

                    _colorTimer -= _colorChangeTime;
                }

                if (_immunTimeLeft <= 0)
                {
                    curGameState   = GameState.Game;
                    _immunTimeLeft = _immunTimeStart = 0;
                    immunTimeGameObj.SetActive(false);
                    _headSR.color = _defaultColor;
                    foreach (var item in _tail)
                    {
                        item.transform.GetComponent <SpriteRenderer>().color = _defaultColor;
                    }
                }
            }

            //if (_isDirChanged)
            //{
            //    Move();
            //    _nextMove = Time.time + _speed;
            //    _isDirChanged = false;
            //    //Debug.Log("On Swipe");
            //}

            if (Time.time > _noMoveTime)
            {
                if (_dirList.Count > 1 && _isDirChanged)
                {
                    //Debug.Log($"Moved by (_dirList.Count > 1): Count = {_dirList.Count}. Time = {Time.time}");
                    _nextMove     = Time.time + _speed;
                    _noMoveTime   = Time.time + _minMoveDelay;
                    _isDirChanged = false;
                    Move();
                }
                else if (Time.time > _nextMove)
                {
                    //Debug.Log($"Moved by (Time.time > _nextMove). Time = {Time.time}");
                    _nextMove   = Time.time + _speed;
                    _noMoveTime = Time.time + _minMoveDelay;
                    Move();
                }
            }
        }
    }