Пример #1
0
    void Fight()
    {
        ContactFilter2D contactFilter = new ContactFilter2D();

        contactFilter.SetLayerMask(LayerMask.GetMask("Enemy"));

        int numColliders = 10;

        Collider2D[] colliders = new Collider2D[numColliders];
        playerCC.OverlapCollider(contactFilter, colliders);

        timeLeft -= Time.deltaTime;
        if (!timerOn)
        {
            timerOn = true; timeLeft = .3f; animator.SetTrigger("Fight");
        }
        if (timerOn && timeLeft <= 0)
        {
            timerOn = false;
        }

        if (colliders[0] != null)
        {
            if (colliders.Any(x => x.GetComponent <Monster>()))
            {
                Monster monster; monster = colliders[0].GetComponent <Monster>(); monster.ReceiveDamage();
            }
        }

        attack = false;
    }
Пример #2
0
 /// <summary>
 /// returns layer index of ground
 /// </summary>
 /// <returns>-1 if not found</returns>
 int GetGroundLayer()
 {
     Collider2D[] results = new Collider2D[1];
     groundCheckCollider.OverlapCollider(new ContactFilter2D {
         layerMask = groundCheckLayers, useLayerMask = true
     }, results);
     if (results.Any(r => r != null))
     {
         return(results.First().gameObject.layer);
     }
     return(-1);
 }
Пример #3
0
 bool IsFrontFacingWall()
 {
     Collider2D[] results = new Collider2D[1];
     frontWallCheckCollider.OverlapCollider(new ContactFilter2D {
         layerMask = wallCheckLayers, useLayerMask = true
     }, results);
     if (results.Any(r => r != null))
     {
         return(true);
     }
     return(false);
 }
Пример #4
0
 bool IsGrounded()
 {
     Collider2D[] results = new Collider2D[1];
     groundCheckCollider.OverlapCollider(new ContactFilter2D {
         layerMask = groundCheckLayers, useLayerMask = true
     }, results);
     if (results.Any(r => r != null))
     {
         return(true);
     }
     return(false);
 }
Пример #5
0
    bool IsEnemyInRange(EnemyScript enemy)
    {
        Collider2D[] results = new Collider2D[ColliderResultSize];
        foreach (Collider2D collider in Colliders)
        {
            ContactFilter2D filter        = new ContactFilter2D();
            int             overlapResult = Physics2D.OverlapCollider(collider, filter, results);
            //Debug.Log($"OR {overlapResult} ResCount {results.Count(r => r != null)}");

            if (overlapResult > 0)
            {
                if (results.Any(r => r != null && r.gameObject.GetInstanceID() == enemy.GetInstanceID()))
                {
                    return(true);
                }
            }
            Array.Clear(results, 0, ColliderResultSize);
        }
        return(false);
    }
Пример #6
0
        /// <summary>
        /// Check for new enemies in radius and attacks if there are.
        /// </summary>
        private void Update()
        {
            // Don't do anything if no enemy is in range
            var results = new Collider2D[128];

            Physics2D.OverlapCircleNonAlloc(transform.position, range.GetStat(), results);
            if (!results.Any(x =>
                             x != null && x.CompareTag(enemyTag)))
            {
                fireCountdown -= Time.deltaTime;
                return;
            }

            // If our attack is off cooldown
            if (fireCountdown <= 0)
            {
                fireCountdown = 1 / fireRate.GetStat();
                Attack();
            }

            fireCountdown -= Time.deltaTime;
        }
Пример #7
0
    private IEnumerator FinishTurn()
    {
        var circleCollider = _activeCoin.GetComponent <CircleCollider2D>();

        var results = new Collider2D[4];

        circleCollider.OverlapCollider(new ContactFilter2D(), results);

        if (!results.Any())
        {
            yield break;
        }

        Collider2D closestCollider = null;
        var        closestDistance = float.MaxValue;

        foreach (var result in results.Where(it => it != null))
        {
            var thisPosition  = circleCollider.bounds.center;
            var otherPosition = result.bounds.center;

            var distance = Vector3.Distance(thisPosition, otherPosition);

            if (distance < closestDistance)
            {
                closestCollider = result;
                closestDistance = distance;
            }
        }

        if (closestCollider != null)
        {
            var colisionObjectRender = closestCollider.gameObject.GetComponent <SpriteRenderer>();
            var tile     = closestCollider.GetComponent <Tile>();
            var tileText = tile.transform.Find("tileText").GetComponent <TextMesh>();

            if (_stacking && colisionObjectRender.color.Equals(_activeColor)) // Increase tile stack count if stacking enabled
            {
                tile.Stack   += 1;
                tileText.text = tile.Stack.ToString();
            }
            else if (_stacking && tile.Stack.HasValue && tile.Stack.Value > 1) // Decrease tile stack if stacking enabled
            {
                tile.Stack   -= 1;
                tileText.text = tile.Stack.ToString();
            }
            else // Swap colour if stealing enabled. Set stack count to 1 if stacking enabled
            {
                if (_stealing || !_playerColours.Any(it => it.Equals(colisionObjectRender.color)))
                {
                    //Alter the animation curve so that we fade from the color it is the color we want
                    var a = closestCollider.GetComponent <Animation>();
                    var existingClipLength = a.clip.length;

                    var rCurve = AnimationCurve.EaseInOut(0, colisionObjectRender.color.r, existingClipLength, _activeColor.r);
                    var gCurve = AnimationCurve.EaseInOut(0, colisionObjectRender.color.g, existingClipLength, _activeColor.g);
                    var bCurve = AnimationCurve.EaseInOut(0, colisionObjectRender.color.b, existingClipLength, _activeColor.b);
                    var aCurve = AnimationCurve.EaseInOut(0, colisionObjectRender.color.a, existingClipLength, _activeColor.a);

                    a.clip.SetCurve("", typeof(SpriteRenderer), "m_Color.r", rCurve);
                    a.clip.SetCurve("", typeof(SpriteRenderer), "m_Color.g", gCurve);
                    a.clip.SetCurve("", typeof(SpriteRenderer), "m_Color.b", bCurve);
                    a.clip.SetCurve("", typeof(SpriteRenderer), "m_Color.a", aCurve);

                    a.Play();
                }

                if (_stacking)
                {
                    tile.Stack    = 1;
                    tileText.text = tile.Stack.ToString();
                }
            }

            // Remember the change
            _board[tile.Row, tile.Col].Color = ColorUtility.ToHtmlStringRGBA(_activeColor);
            _activeTile = tile;
        }

        _activeCoin.GetComponent <CoinMovementManager>().ShrinkAudio.Play();
        _activeCoin.GetComponent <Animation>().Play("Shrink");

        yield return(new WaitForSeconds(0.5f));

        Destroy(_activeCoin);
    }