Exemple #1
0
    private IEnumerator GetBackIntoBattle()
    {
        SetAnimationState((int)EnemyAnimationState.Idle);
        TDS_Bounds _bounds = TDS_Camera.Instance?.CurrentBounds;
        Vector3    _pos    = Vector3.zero;

        if (_bounds == null)
        {
            _pos = TDS_LevelManager.Instance.AllPlayers.FirstOrDefault().transform.position;
        }
        else
        {
            _pos = new Vector3((_bounds.XMax + _bounds.XMin) / 2, 0, (_bounds.ZMin + _bounds.ZMax) / 2);
        }
        //Reinstantiate the particle here
        TDS_VFXManager.Instance.SpawnEffect(FXType.MrLoyalTeleportation, transform.position);
        yield return(new WaitForSeconds(1.25f));

        sprite.enabled     = false;
        transform.position = _pos;
        TDS_VFXManager.Instance.SpawnEffect(FXType.MrLoyalEndTeleportation, _pos);
        yield return(null);

        sprite.enabled = true;
        yield return(null);

        //ActivateEnemy();
        SetEnemyState(EnemyState.MakingDecision);
        Invoke("PlayRandomTaunt", Random.Range(tauntRateMin, tauntRateMax));
        if (isEnraged)
        {
            cats.ToList().ForEach(c => c.SetCatIndependant());
        }
    }
Exemple #2
0
    /// <summary>
    /// Set new bounds for the camera.
    /// </summary>
    /// <param name="_levelBounds">New level bounds.</param>
    public void SetBounds(TDS_LevelBounds _levelBounds)
    {
        TDS_Bounds _bounds = new TDS_Bounds(_levelBounds.LeftBound.x != 0 ?
                                            _levelBounds.LeftBound :
                                            currentBounds.XMinVector,

                                            _levelBounds.RightBound.x != 0 ?
                                            _levelBounds.RightBound :
                                            currentBounds.XMaxVector,

                                            _levelBounds.BottomBound.z != 0 ?
                                            _levelBounds.BottomBound :
                                            currentBounds.ZMinVector,

                                            _levelBounds.TopBound.z != 0 ?
                                            _levelBounds.TopBound :
                                            currentBounds.ZMaxVector);

        if (currentBounds == _bounds)
        {
            return;
        }

        if (setBoundsCoroutine != null)
        {
            StopCoroutine(setBoundsCoroutine);
        }
        setBoundsCoroutine = StartCoroutine(SetBoundsInTime(_bounds));
    }
Exemple #3
0
 // Use this for initialization
 protected override void Start()
 {
     bounds = TDS_Camera.Instance?.CurrentBounds;
     hasReachedRightBound = Mathf.Abs(transform.position.x - bounds.XMin) >= Mathf.Abs(transform.position.x - bounds.XMax) ? true : false;
     base.Start();
     SetEnemyState(EnemyState.MakingDecision);
     StartCoroutine(ResetAttackCoolDown());
 }
    /// <summary>
    /// Teleports the given object into actual game zone.
    /// </summary>
    /// <param name="_object"></param>
    public void Teleport(Collider _object)
    {
        TDS_Bounds _bounds         = TDS_Camera.Instance.CurrentBounds;
        Vector3    _actualPosition = _object.transform.position;

        Vector3 _newPosition = new Vector3(_object.bounds.min.x <_bounds.XMin ? (_bounds.XMin + _object.bounds.size.x + 1) : _object.bounds.max.x> _bounds.XMax ?                                       (_bounds.XMax - _object.bounds.size.x - 1) : _actualPosition.x,
                                           _object.bounds.min.y < 0 ? 2.5f : _actualPosition.y,
                                           _object.bounds.min.z <_bounds.ZMin ? (_bounds.ZMin + _object.bounds.size.z + 1) : _object.bounds.max.z> _bounds.ZMax ? (_bounds.ZMax - _object.bounds.size.z - 1) : _actualPosition.z);

        _object.transform.position = _newPosition;
    }
Exemple #5
0
    // Use this for initialization
    private void Start()
    {
        // Set default level bounds
        levelBounds   = new TDS_Bounds(leftBound.transform.position, rightBound.transform.position, bottomBound.transform.position, topBound.transform.position);
        currentBounds = levelBounds;

        // Set previous position as current one
        previousPosition = transform.position;

        // Set the camera position between bounds
        ClampInBounds();
    }
 public override void ApplyAttackBehaviour(TDS_Enemy _caster)
 {
     caster              = _caster;
     caster.Agent.Speed  = spinningSpeed;
     casterInitialRadius = caster.Agent.Radius;
     caster.Agent.Radius = spinningRadius;
     if (spinningPositions == null || spinningPositions.Length == 0)
     {
         TDS_Bounds _bounds = TDS_Camera.Instance.CurrentBounds;
         spinningPositions = new Vector3[5] {
             new Vector3(_bounds.XMin + 1, 0, _bounds.ZMax - 1),
             new Vector3(_bounds.XMin + 1, 0, _bounds.ZMin + 1),
             new Vector3(_bounds.XMax - 1, 0, _bounds.ZMax - 1),
             new Vector3(_bounds.XMax - 1, 0, _bounds.ZMin + 1),
             new Vector3((_bounds.XMin + _bounds.XMax) / 2, 0, (_bounds.ZMin + _bounds.ZMax) / 2)
         };
     }
     caster.Agent.OnDestinationReached += GoNextSpinningPosition;
     GoNextSpinningPosition();
 }
Exemple #7
0
    /// <summary>
    /// Wait to set bounds if minimum x value is visible by the camera or to its right.
    /// </summary>
    /// <param name="_bounds">Bounds to set.</param>
    /// <returns></returns>
    private IEnumerator SetBoundsInTime(TDS_Bounds _bounds)
    {
        // Get the movement direction of the bounds
        int[] _boundsMovement = new int[4];

        _boundsMovement[0] = _bounds.XMin > currentBounds.XMin ? 1 : _bounds.XMin < currentBounds.XMin ? -1 : 0;

        _boundsMovement[1] = _bounds.XMax > currentBounds.XMax ? 1 : _bounds.XMax < currentBounds.XMax ? -1 : 0;

        _boundsMovement[2] = _bounds.ZMin > currentBounds.ZMin ? 1 : _bounds.ZMin < currentBounds.ZMin ? -1 : 0;

        _boundsMovement[3] = _bounds.ZMax > currentBounds.ZMax ? 1 : _bounds.ZMax < currentBounds.ZMax ? -1 : 0;

        Vector3 _localPlayerPosition = new Vector3();

        Vector3[] _playerPositions = new Vector3[TDS_LevelManager.Instance.OtherPlayers.Count];

        // While all the bounds are not in the right place, set their position
        while (_boundsMovement.Any(m => m != 0))
        {
            // Get all players position
            if (!PhotonNetwork.offlineMode)
            {
                _localPlayerPosition = TDS_LevelManager.Instance.LocalPlayer.transform.position;
                for (int _i = 0; _i < TDS_LevelManager.Instance.OtherPlayers.Count; _i++)
                {
                    _playerPositions[_i] = TDS_LevelManager.Instance.OtherPlayers[_i].transform.position;
                }
            }

            // Left bound move
            if (_boundsMovement[0] != 0)
            {
                if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.x > _localPlayerPosition.x))
                {
                    float _xMin = camera.WorldToViewportPoint(_bounds.XMinVector).x;
                    if (_xMin < .0001f)
                    {
                        leftBoundVector    = _bounds.XMinVector;
                        _boundsMovement[0] = 0;

                        OnXMinBoundChanged?.Invoke();

                        // Set X Min bound value to send online
                        onlineSendingBounds.x = currentBounds.XMin;
                    }
                    else
                    {
                        _xMin = transform.position.x - CameraXRatio;
                        if (_xMin != currentBounds.XMin)
                        {
                            leftBoundVector = new Vector3(_xMin, leftBound.transform.position.y, leftBound.transform.position.z);

                            OnXMinBoundChanged?.Invoke();

                            // Set X Min bound value to send online
                            onlineSendingBounds.x = currentBounds.XMin;
                        }
                    }
                }
                else if (currentBounds.XMin == _bounds.XMin)
                {
                    _boundsMovement[0] = 0;
                }
            }
            // Right bound move
            if (_boundsMovement[1] != 0)
            {
                if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.x < _localPlayerPosition.x))
                {
                    float _xMax = camera.WorldToViewportPoint(_bounds.XMaxVector).x;
                    if (_xMax > .9999f)
                    {
                        rightBoundVector   = _bounds.XMaxVector;
                        _boundsMovement[1] = 0;

                        // Set X Max bound value to send online
                        onlineSendingBounds.y = currentBounds.XMax;
                    }
                    else
                    {
                        _xMax = transform.position.x + CameraXRatio;
                        if (_xMax != currentBounds.XMax)
                        {
                            rightBoundVector = new Vector3(_xMax, rightBound.transform.position.y, rightBound.transform.position.z);

                            // Set X Max bound value to send online
                            onlineSendingBounds.y = currentBounds.XMax;
                        }
                    }
                }
                else if (currentBounds.XMax == _bounds.XMax)
                {
                    _boundsMovement[1] = 0;
                }
            }
            // Bottom bound move
            if (_boundsMovement[2] != 0)
            {
                if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.z > _localPlayerPosition.z))
                {
                    float _zMin = camera.WorldToViewportPoint(_bounds.ZMinVector).y;
                    if (_zMin < .0001f)
                    {
                        bottomBoundVector  = _bounds.ZMinVector;
                        _boundsMovement[2] = 0;

                        // Set Z Min bound value to send online
                        onlineSendingBounds.z = currentBounds.ZMin;
                    }
                    else
                    {
                        _zMin = bottomBound.transform.position.z - (camera.orthographicSize * 2 * camera.WorldToViewportPoint(currentBounds.ZMinVector).y *VIEWPORT_CALCL_Y_COEF);
                        if (_zMin != currentBounds.ZMin)
                        {
                            bottomBoundVector = new Vector3(bottomBound.transform.position.x, bottomBound.transform.position.y, _zMin);

                            // Set Z Min bound value to send online
                            onlineSendingBounds.z = currentBounds.ZMin;
                        }
                    }
                }
                else if (currentBounds.ZMin == _bounds.ZMin)
                {
                    _boundsMovement[2] = 0;
                }
            }
            // Top bound move
            if (_boundsMovement[3] != 0)
            {
                if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.z < _localPlayerPosition.z))
                {
                    float _mostUpPlayer = PhotonNetwork.offlineMode ? players.OrderBy(p => p.transform.position.z).Last().transform.position.z : target.position.z;

                    float _zMax = camera.WorldToViewportPoint(_bounds.ZMaxVector).y;
                    if ((_zMax > (ViewportYMacBoundValue - .0001f)) && (_mostUpPlayer + 1 < _bounds.ZMax))
                    {
                        topBoundVector     = _bounds.ZMaxVector;
                        _boundsMovement[3] = 0;

                        // Set Z Max bound value to send online
                        onlineSendingBounds.w = currentBounds.ZMax;
                    }
                    else
                    {
                        _zMax = topBound.transform.position.z + (camera.orthographicSize * 2 * (ViewportYMacBoundValue - camera.WorldToViewportPoint(currentBounds.ZMaxVector).y) * VIEWPORT_CALCL_Y_COEF);

                        if ((_zMax != currentBounds.ZMax) && (_mostUpPlayer + 1 < _zMax))
                        {
                            topBoundVector = new Vector3(topBound.transform.position.x, topBound.transform.position.y, _zMax);

                            // Set Z Max bound value to send online
                            onlineSendingBounds.w = currentBounds.ZMax;
                        }
                    }
                }
                else if (currentBounds.ZMax == _bounds.ZMax)
                {
                    _boundsMovement[3] = 0;
                }
            }

            yield return(null);
        }

        setBoundsCoroutine = null;
    }