private IEnumerator NewShapeEffectCorutine(ShapeScriptable _newShape)
    {
        float animDur           = 0.03f;
        int   currentShapeIndex = ShapeController.GetCurrentShapeIndex();

        readInput = false;
        Direction randomDir = UnityEngine.Random.Range(0, 2) == 0 ? Direction.Right : Direction.Left;

        for (int i = 0; i < 15; i++)
        {
            gameplayPanel.UpdateShape(randomDir, ShapeController.GetShapeByIndex(currentShapeIndex), ShapeController.GetShapeByIndex(currentShapeIndex - 1), ShapeController.GetShapeByIndex(currentShapeIndex + 1), true, animDur);
            currentShapeIndex++;

            if (randomDir == Direction.Right)
            {
                SwipeController.RightSwipe();
            }
            else
            {
                SwipeController.LeftSwipe();
            }

            yield return(new WaitForSeconds(animDur));
        }

        shapeCtrl.ChangeShape(_newShape);
        readInput = true;
    }
    public void StartSpawn(ShapeScriptable _firstShape = null)
    {
        ShapeController.OnNewShapeAdd += HandleOnNewShapeAdd;
        ShapeMatch.ShapeDestroied     += HandleShapeDestroyed;
        nextShape = null;

        spawnWaveRoutine = SpawnShapeCoroutine(_firstShape);
        StartCoroutine(spawnWaveRoutine);
    }
示例#3
0
    public void DestroyShape()
    {
        ShapeDestroied?.Invoke(this);
        OnObjectDestroy?.Invoke(this);

        shape             = null;
        spriteMask.sprite = null;
        isSetupped        = false;
    }
示例#4
0
 public static void AddNewShape()
 {
     if (i.shapesToAdd != null && i.shapesToAdd.Count > 0)
     {
         i.shapeGuessed = 0;
         ShapeScriptable shapeToAdd = i.shapesToAdd[0].shape;
         i.shapesToAdd.RemoveAt(0);
         i.currentShapes.Add(shapeToAdd);
         OnNewShapeAdd?.Invoke(shapeToAdd);
     }
 }
示例#5
0
    public void Setup(ShapeScriptable _shape, Camera _cam)
    {
        shape                 = _shape;
        spriteMask            = GetComponent <SpriteMask>();
        spriteRenderer        = GetComponent <SpriteRenderer>();
        spriteRenderer.sprite = shape.guessShapeSprite;
        bound                 = _cam.GetOrthographicBounds();

        OnObjectSpawn?.Invoke(this);
        isToGuess  = true;
        isSetupped = true;
    }
示例#6
0
    public static int GetIndexByShape(ShapeScriptable _shape)
    {
        for (int j = 0; j < i.currentShapes.Count; j++)
        {
            if (i.currentShapes[j] == _shape)
            {
                return(j);
            }
        }

        return(0);
    }
    public void StopSpawn()
    {
        if (spawnWaveRoutine != null)
        {
            StopCoroutine(spawnWaveRoutine);
        }

        DestroyShapes();
        nextShape = null;

        ShapeController.OnNewShapeAdd -= HandleOnNewShapeAdd;
        ShapeMatch.ShapeDestroied     -= HandleShapeDestroyed;
    }
示例#8
0
    public bool CheckShape(ShapeScriptable _shape)
    {
        isToGuess = false;

        if (ShapeController.GetCurrentShape() == shape)
        {
            spriteMask.sprite     = shape.shadowSprite;
            spriteRenderer.sprite = shape.shapeSprite;
            return(true);
        }

        return(false);
    }
示例#9
0
    public void ChangeShape(Direction _swipeDir, bool _animation)
    {
        switch (_swipeDir)
        {
        case Direction.Right:
            shapeIndex = FixShapeIndex(GetCurrentShapeIndex() - 1);
            break;

        case Direction.Left:
            shapeIndex = FixShapeIndex(GetCurrentShapeIndex() + 1);
            break;
        }

        ShapeScriptable newShape = GetShapeByIndex(shapeIndex);

        OnShapeChanged?.Invoke(_swipeDir, newShape, _animation);
    }
    public void SpawnShape(ShapeScriptable _shapeToSpawn)
    {
        //Calculate Random Position
        float   randomXValue = UnityEngine.Random.Range((bgBounds.center.x - bgBounds.extents.x) + 1f, (bgBounds.center.x + bgBounds.extents.x) - 1f);
        Vector3 spawnVector  = new Vector3(randomXValue, transform.position.y, transform.position.z);

        //Calculate Random Rotation
        float      randomRoation = UnityEngine.Random.Range(-60f, 60f);
        Quaternion spawnRotation = Quaternion.Euler(0, 0, randomRoation);

        ShapeMatch newShape = PoolManager.instance.GetPooledObject(ObjectTypes.Shape, gameObject).GetComponent <ShapeMatch>();

        if (newShape != null)
        {
            newShape.transform.SetPositionAndRotation(spawnVector, spawnRotation);
            newShape.Setup(_shapeToSpawn, cam);
            spawnedShapes.Add(newShape);
        }
    }
示例#11
0
    public void UpdateShape(Direction _swipeDir, ShapeScriptable _currentShape, ShapeScriptable _previousShape, ShapeScriptable _nextShape, bool _animation, float _animTime = 0f)
    {
        if (_animation)
        {
            changeShapeRoutine = ChangeShapeCoroutine(_swipeDir, _currentShape, _previousShape, _nextShape, _animTime);
            StartCoroutine(changeShapeRoutine);
        }
        else
        {
            if (changeShapeRoutine != null)
            {
                StopCoroutine(changeShapeRoutine);
            }

            ResetUIPos();

            rightShape.sprite  = _nextShape.uiShapeSprite;
            centerShape.sprite = _currentShape.uiShapeSprite;
            leftShape.sprite   = _previousShape.uiShapeSprite;
        }
    }
    private IEnumerator SpawnShapeCoroutine(ShapeScriptable _firstShape)
    {
        yield return(new WaitForSeconds(startDelayTime));

        while (true)
        {
            ShapeScriptable shapeToSpawn;
            if (nextShape != null)
            {
                shapeToSpawn = nextShape;
                nextShape    = null;

                yield return(new WaitForSeconds(0.7f));
            }
            else if (_firstShape != null)
            {
                shapeToSpawn = _firstShape;
                _firstShape  = null;
            }
            else
            {
                int shapeToGuess = spawnedShapes.Count(s => s.IsToGuess());
                if (ShapeController.CheckNextShapeToAdd(shapeToGuess))
                {
                    yield return(null);

                    continue;
                }

                shapeToSpawn = ShapeController.GetRandomShapeMatch();
            }

            SpawnShape(shapeToSpawn);

            yield return(new WaitForSeconds(DifficultyManager.GetCurrentSpawnRate()));
        }
    }
 private void HandleOnNewShapeAdd(ShapeScriptable _newShape)
 {
     nextShape = _newShape;
 }
示例#14
0
 public void ChangeShape(ShapeScriptable _shape)
 {
     shapeIndex = GetIndexByShape(_shape);
     OnShapeChanged?.Invoke(Direction.None, _shape, false);
 }
 private void HandleOnNewShapeAdd(ShapeScriptable _newShape)
 {
     shapeCtrl.StartCoroutine(NewShapeEffectCorutine(_newShape));
 }
    private void HandleOnShapeChange(Direction _swipeDir, ShapeScriptable _newShape, bool _animation)
    {
        int currentShapeIndex = ShapeController.GetCurrentShapeIndex();

        gameplayPanel.UpdateShape(_swipeDir, _newShape, ShapeController.GetShapeByIndex(currentShapeIndex - 1), ShapeController.GetShapeByIndex(currentShapeIndex + 1), _animation, changeShapeDelayTime);
    }
示例#17
0
    private IEnumerator ChangeShapeCoroutine(Direction _swipeDir, ShapeScriptable _currentShape, ShapeScriptable _previousShape, ShapeScriptable _nextShape, float _animTime)
    {
        switch (_swipeDir)
        {
        case Direction.Right:
            //Imposto la shape jolly iniziale
            newShape.transform.position = extremeLeftPos.position;
            newShape.transform.rotation = extremeLeftPos.rotation;
            newShape.sprite             = _nextShape.uiShapeSprite;

            //Creo tutti i Tween per ogni forma posizionarsi rispetto allo swipe
            Tween newShapeToCenterPosR         = newShape.transform.DOMove(leftStartPos, _animTime).SetEase(Ease.Linear);
            Tween newShapeToCenterRotR         = newShape.transform.DORotateQuaternion(leftStartRot, _animTime).SetEase(Ease.Linear);
            Tween leftToCenterPosR             = leftShape.transform.DOMove(centerStartPos, _animTime).SetEase(Ease.Linear);
            Tween leftToCenterRotR             = leftShape.transform.DORotateQuaternion(centerStartRot, _animTime).SetEase(Ease.Linear);
            Tween centerToRightTweenPosR       = centerShape.transform.DOMove(rightStartPos, _animTime).SetEase(Ease.Linear);
            Tween centerToRightTweenRotR       = centerShape.transform.DORotateQuaternion(rightStartRot, _animTime).SetEase(Ease.Linear);
            Tween rightToExtremeRightTweenPosR = rightShape.transform.DOMove(extremeRightPos.position, _animTime).SetEase(Ease.Linear);
            Tween rightToExtremeRightTweenRotR = rightShape.transform.DORotateQuaternion(extremeRightPos.rotation, _animTime).SetEase(Ease.Linear);

            //Assegno i Tween alla sequenza
            Sequence rightSequence = DOTween.Sequence();

            rightSequence.Append(newShapeToCenterPosR);
            rightSequence.Insert(0, newShapeToCenterRotR);
            rightSequence.Insert(0, leftToCenterPosR);
            rightSequence.Insert(0, leftToCenterRotR);
            rightSequence.Insert(0, centerToRightTweenPosR);
            rightSequence.Insert(0, centerToRightTweenRotR);
            rightSequence.Insert(0, rightToExtremeRightTweenPosR);
            rightSequence.Insert(0, rightToExtremeRightTweenRotR);

            //Eseguo la sequenza e  aspetto il completamento
            rightSequence.Play();
            yield return(rightSequence.WaitForCompletion());

            //Rimetto ogni shape nella sua giusta posizione e gli assegno la nuova sprites
            rightShape.transform.position = rightStartPos;
            rightShape.transform.rotation = rightStartRot;
            rightShape.sprite             = _nextShape.uiShapeSprite;

            centerShape.transform.position = centerStartPos;
            centerShape.transform.rotation = centerStartRot;
            centerShape.sprite             = _currentShape.uiShapeSprite;

            leftShape.transform.position = leftStartPos;
            leftShape.transform.rotation = leftStartRot;
            leftShape.sprite             = _previousShape.uiShapeSprite;

            newShape.transform.position = newStartPos;
            newShape.transform.rotation = newStartRot;
            break;

        case Direction.Left:
            //Imposto la shape jolly iniziale
            newShape.transform.position = extremeRightPos.position;
            newShape.transform.rotation = extremeRightPos.rotation;
            newShape.sprite             = _previousShape.uiShapeSprite;

            //Creo tutti i Tween per ogni forma posizionarsi rispetto allo swipe
            Tween newShapeToCenterPosL      = newShape.transform.DOMove(rightStartPos, _animTime).SetEase(Ease.Linear);
            Tween newShapeToCenterRotL      = newShape.transform.DORotateQuaternion(rightStartRot, _animTime).SetEase(Ease.Linear);
            Tween rightToCenterPosL         = rightShape.transform.DOMove(centerStartPos, _animTime).SetEase(Ease.Linear);
            Tween rightToCenterRotL         = rightShape.transform.DORotateQuaternion(centerStartRot, _animTime).SetEase(Ease.Linear);
            Tween leftToCenterPosL          = centerShape.transform.DOMove(leftStartPos, _animTime).SetEase(Ease.Linear);
            Tween leftToCenterRotL          = centerShape.transform.DORotateQuaternion(leftStartRot, _animTime).SetEase(Ease.Linear);
            Tween leftToExtremeLeftTweenPos = leftShape.transform.DOMove(extremeLeftPos.position, _animTime).SetEase(Ease.Linear);
            Tween leftToExtremeLeftTweenRot = leftShape.transform.DORotateQuaternion(extremeLeftPos.rotation, _animTime).SetEase(Ease.Linear);

            //Assegno i Tween alla sequenza
            Sequence lSequence = DOTween.Sequence();

            lSequence.Append(newShapeToCenterPosL);
            lSequence.Insert(0, newShapeToCenterRotL);
            lSequence.Insert(0, rightToCenterPosL);
            lSequence.Insert(0, rightToCenterRotL);
            lSequence.Insert(0, leftToCenterPosL);
            lSequence.Insert(0, leftToCenterRotL);
            lSequence.Insert(0, leftToExtremeLeftTweenPos);
            lSequence.Insert(0, leftToExtremeLeftTweenRot);

            //Eseguo la sequenza e  aspetto il completamento
            lSequence.Play();
            yield return(lSequence.WaitForCompletion());

            //Rimetto ogni shape nella sua giusta posizione e gli assegno la nuova sprites
            leftShape.transform.position = leftStartPos;
            leftShape.transform.rotation = leftStartRot;
            leftShape.sprite             = _previousShape.uiShapeSprite;

            centerShape.transform.position = centerStartPos;
            centerShape.transform.rotation = centerStartRot;
            centerShape.sprite             = _currentShape.uiShapeSprite;

            rightShape.transform.position = rightStartPos;
            rightShape.transform.rotation = rightStartRot;
            rightShape.sprite             = _nextShape.uiShapeSprite;

            newShape.transform.position = newStartPos;
            newShape.transform.rotation = newStartRot;
            break;
        }
    }
示例#18
0
 private void HandleOnNewShapeAdd(ShapeScriptable _newShape)
 {
     newShapeFeedbackRoutine = NewShapeFeedbackCoroutine();
     StartCoroutine(newShapeFeedbackRoutine);
 }