Beispiel #1
0
    public override void AttackDamage()
    {
        Collider2D[] collider2Ds = Physics2D.OverlapBoxAll(transform.position, boxCollider2D.size, 0.0f, _hitLayerMask);
        isEnter = false;
        foreach (var item in collider2Ds)
        {
            if (item.gameObject.name.Contains("Player"))
            {
                continue;
            }

            if (item.gameObject.tag == "Skill")
            {
                Debug.Log("asdasdasd");
                // Skill1
                item.GetComponent <Skill1Ctrl>().SetSkill1Ex();
            }

            if (item.CompareTag("Enemy") /*&& item.GetComponent<UnitBase>().Status.isAlive*/)
            {
                isEnter = true;

                //크리티컬 확률 계산
                float criticalRoulette = Random.Range(0, 100);
                bool  isCritical       = (_criticalPercentage > criticalRoulette) ? true : false;

                if (isCritical)
                {
                    item.GetComponent <UnitBase>().Hit(damage * 1.5f);
                }
                else
                {
                    item.GetComponent <UnitBase>().Hit(damage);
                }
            }
        }
    }
Beispiel #2
0
    public override string BEOperation(BETargetObject targetObject, BEBlock beBlock)
    {
        if (targetObject.GetComponent <Collider2D>())
        {
            Collider2D[] hitColliders = Physics2D.OverlapBoxAll(targetObject.transform.position, transform.localScale / 2, 0);
            int          i            = 0;

            while (i < hitColliders.Length)
            {
                value = "0";
                if (beBlock.BeInputs.stringValues[0] == hitColliders[i].tag)
                {
                    value = "1";
                    break;
                }
                i++;
            }
        }
        else if (targetObject.GetComponent <Collider>())
        {
            Collider[] hitColliders = Physics.OverlapBox(targetObject.transform.position, transform.localScale / 2, Quaternion.identity);
            int        i            = 0;

            while (i < hitColliders.Length)
            {
                value = "0";
                if (beBlock.BeInputs.stringValues[0] == hitColliders[i].tag)
                {
                    value = "1";
                    break;
                }
                i++;
            }
        }

        return(value);
    }
Beispiel #3
0
    private IEnumerator swingWhip()
    {
        /* Author: Reynaldo Hermawan
         * Description: Checks if the whip hit anything and aapplies damage based on hit. Whip has 2 hitboxes with different damage values.
         */
        anim.SetTrigger("Swing");
        if (!GameControl.instance.paused)
        {
            sound.Play();
        }
        yield return(new WaitForSeconds(.28f));

        Collider2D[] peopleTipHit = Physics2D.OverlapBoxAll(attackTipPos.position, new Vector2(attackTipRangeX, attackTipRangeY), 0, otherPlayers);
        if (peopleTipHit.Length > 0)
        {
            for (int i = 0; i < peopleTipHit.Length; i++)
            {
                if (peopleTipHit[i].gameObject != this.player)
                {
                    peopleTipHit[i].GetComponent <PlayerController>().receiveDamage(damageTip);
                    peopleTipHit[i].GetComponent <Rigidbody2D>().AddForce(new Vector2(knockbackTip * player.transform.localScale.x, 800));
                }
            }
        }
        else
        {
            Collider2D[] peopleWhipHit = Physics2D.OverlapBoxAll(attackWhipPos.position, new Vector2(attackWhipRangeX, attackWhipRangeY), 0, otherPlayers);
            for (int i = 0; i < peopleWhipHit.Length; i++)
            {
                if (peopleWhipHit[i].gameObject != this.player)
                {
                    peopleWhipHit[i].GetComponent <PlayerController>().receiveDamage(damageWhip);
                    peopleWhipHit[i].GetComponent <Rigidbody2D>().AddForce(new Vector2(knockbackWhip * player.transform.localScale.x, 800));
                }
            }
        }
    }
Beispiel #4
0
    void CheckHurt()
    {
        if (!isInvuln)
        {
            Collider2D[] colliders = Physics2D.OverlapBoxAll(
                ((Vector2)body.transform.position + myCollider.offset),
                (myCollider.size), 0);

            for (int i = 0; i < colliders.Length; i++)
            {
                string tag = colliders[i].gameObject.tag;
                if (tag.Equals("EnemyAttack"))
                {
                    canMove       = false;
                    isKnockedBack = true;
                    isInvuln      = true;
                    health        = Mathf.Clamp(health - 0.5f, 0, 100);
                    healthbar.TakeDamage(0.5f);

                    if (transform.position.x < colliders[i].transform.position.x)
                    {
                        knockback = new Vector2(-1, 3);
                    }
                    else
                    {
                        knockback = new Vector2(1, 3);
                    }

                    recoveryTimer = 0.5f;
                    invulnTimer   = 2;
                    animateHurt   = true;

                    break;
                }
            }
        }
    }
        protected T GetBullet <T>(BoxCollider2D collisn) where T : o_bullet
        {
            if (collisn == null)
            {
                return(null);
            }

            Collider2D[] chara = Physics2D.OverlapBoxAll(transform.position, collisn.size, 0);

            if (chara == null)
            {
                return(null);
            }
            for (int i = 0; i < chara.Length; i++)
            {
                Collider2D co = chara[i];
                if (co.gameObject == gameObject)
                {
                    continue;
                }

                T b = co.gameObject.GetComponent <T>();
                if (b == null)
                {
                    continue;
                }
                if (targets.Find(x => x == b.parent) != null)
                {
                    o_character host = b.parent;
                    if (host != this)
                    {
                        return(b);
                    }
                }
            }
            return(null);
        }
    /**
     * <summary>
     * Watch for the item on top of the belt
     * Move the items to the origin point then move it downward
     * </summary>
     */
    protected override void WatchForItem()
    {
        Bounds  bounds = this.transform.GetComponent <Collider2D>().bounds;
        Vector2 size   = bounds.size;

        Collider2D[] colliders = Physics2D.OverlapBoxAll(this.transform.position, size, 0);
        foreach (Collider2D collider in colliders)
        {
            if (collider.tag == Tags.Item)
            {
                Transform item       = collider.GetComponent <Transform>();
                Bounds    itemBounds = item.GetComponent <Collider2D>().bounds;
                Vector2   itemPoint  = new Vector2(itemBounds.max.x, itemBounds.min.y);

                // Do not move the item if the item point is not on the belt
                if (!bounds.Contains(itemPoint))
                {
                    continue;
                }

                // Has the item reached the origin point?
                if (this.transform.position.x - item.position.x < 0)
                {
                    ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                    itemBehaviour.speed = 5f;
                    itemBehaviour.MoveLeft();
                }
                // If the item has reached the origin point, move up
                else
                {
                    ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                    itemBehaviour.speed = 5f;
                    itemBehaviour.MoveUp();
                }
            }
        }
    }
Beispiel #7
0
    IEnumerator DropRoutine()
    {
        Debug.Log("<color=magenta>DROP ROUTINE ENTER</color>");
//		this.isDropping = true;
        Collider2D[] colliders;
        Vector3      prevPosition = Vector3.zero;
        bool         hasAbsorbed  = false;

        // While falling
        while (!hasAbsorbed &&      //&& gameObject.transform.position != prevPosition
               !this.boxCollider.IsTouchingLayers(LayerMask.NameToLayer("Ground")))
        {
//			this.GetRigidBody2D().velocity.y > 0f) {
//			ContactFilter2D contactFilter = new ContactFilter2D ();
//			Physics2D.OverlapBox (this.boxCollider.transform.position, this.boxCollider.size, this.boxCollider.transform.eulerAngles.z, contactFilter, colliders);
            colliders = Physics2D.OverlapBoxAll(this.boxCollider.transform.position, this.boxCollider.size, this.boxCollider.transform.eulerAngles.z);

            foreach (Collider2D collider in colliders)
            {
                if (!hasAbsorbed && !isCarried &&
                    collider.gameObject.GetComponent <HollowBlock> () != null)
                {
                    // Absorb
                    hasAbsorbed = true;
                    Debug.Log("<color=blue>HOLLOW BLOCK COLLISION</color>");
                    HollowBlock hollowBlock = collider.gameObject.GetComponent <HollowBlock> ();
                    hollowBlock.Absorb(this);
                }
                yield return(null);
            }
            yield return(null);

            prevPosition = gameObject.transform.position;
        }
//		this.isDropping = false;
        Debug.Log("<color=magenta>DROP ROUTINE EXIT</color>");
    }
Beispiel #8
0
    void OnEnable()
    {
        if (transform.rotation == Quaternion.Euler(0f, 0f, 0f))
        {
            headingTo = Vector2.right;
        }
        else if (transform.rotation == Quaternion.Euler(0f, 180f, 0f))
        {
            headingTo = Vector2.left;
        }

        Collider2D[] cols = null;

        if (TryGetComponent(out BoxCollider2D boxcol))
        {
            cols = Physics2D.OverlapBoxAll(transform.position + new Vector3(boxcol.offset.x * headingTo.x, boxcol.offset.y), boxcol.size, 0f, Target);
        }

        if (TryGetComponent(out CircleCollider2D cirlecol))
        {
            cols = Physics2D.OverlapCircleAll(transform.position + new Vector3(cirlecol.offset.x * headingTo.x, cirlecol.offset.y), cirlecol.radius, Target);
        }



        foreach (Collider2D col in cols)
        {
            Vector2 force = new Vector2(headingTo.x * KnockBackPower.x, KnockBackPower.y);

            col.GetComponent <Enemy>().Hurt(NormalDamage, force);
            TimeManager.Instance.SetTimeScaleTimered(0.2f, 0.1f);
            if (SlashEffect)
            {
                Instantiate(SlashEffect, col.transform.position, Quaternion.Euler(0, 0, Random.Range(0f, 359f)));
            }
        }
    }
Beispiel #9
0
        //void OnGUI()
        //{
        //    GUI.Label(new Rect(0, 20, 150, 100), "Monster Panel");
        //    GUI.Label(new Rect(0, 40, 300, 100), "ActiveControl:" + ActiveControl);
        //    GUI.Label(new Rect(0, 60, 300, 100), "gravity:" + gravity);
        //    GUI.Label(new Rect(0, 80, 300, 100), "velocity:" + velocity + controller.velocity);
        //    GUI.Label(new Rect(0, 100, 300, 100), "moveAmount:" + velocity * Time.deltaTime);
        //    GUI.Label(new Rect(0, 120, 300, 100), "left:" + controller.collisionState.left + " " +
        //                                          "right:" + controller.collisionState.right + " " +
        //                                          "below:" + controller.collisionState.below + " " +
        //                                          "above:" + controller.collisionState.above);
        //    GUI.Label(new Rect(0, 140, 300, 100), "faceDir:" + controller.collisionState.faceDir);
        //    GUI.Label(new Rect(0, 160, 300, 100), "FaceDirection:" + FaceDirection);
        //    GUI.Label(new Rect(0, 180, 300, 100), "directionalInput:" + directionalInput);
        //}
#endif

        /// <summary>
        /// 更改faceDir之后需要处理平台碰撞盒与地形的重叠
        /// </summary>
        private void processCollision()
        {
            var center = (Vector2)transform.position + controller.boxCollider.offset;
            var size   = controller.boxCollider.size;

            Collider2D[] obstacles = Physics2D.OverlapBoxAll(center, size, 0, controller.platformMask & ~controller.oneWayPlatformMask);

            foreach (var obstacle in obstacles)
            {
                // 忽略脚下
                if (obstacle.bounds.max.y <= controller.boxCollider.bounds.min.y + controller.skinWidth)
                {
                    continue;
                }

                // 判断障碍在左边还是右边
                int obstacleDir = obstacle.bounds.center.x > center.x ? 1 : -1;

                // 如果障碍物在右边,则把位置向左移动,直到不再与地形相交
                if (obstacleDir == 1)
                {
                    var offsetX = (center.x + size.x / 2) - obstacle.bounds.min.x;
                    //transform.SetPosition(transform.position.x - offsetX, null, null);
                    controller.Move(new Vector2(-offsetX, 0f));
                    //Debug.Log($"processCollision() Right {obstacle.transform.GetPath()}");
                    return;
                }
                else
                {
                    var offsetX = obstacle.bounds.max.x - (center.x - size.x / 2);
                    //transform.SetPosition(transform.position.x + offsetX, null, null);
                    controller.Move(new Vector2(offsetX, 0f));
                    //Debug.Log($"processCollision() Left {obstacle.transform.GetPath()}");
                    return;
                }
            }
        }
Beispiel #10
0
    // Update is called once per frame
    void Update()
    {
        if (_triggered)
        {
            GetComponent <Renderer>().material = SpikeTrapTriggeredMaterial;
            if (_activationTimer <= 0)
            {
                _active          = true;
                _triggered       = false;
                _activationTimer = ActivationTime;
                GetComponent <Renderer>().material = SpikeTrapActiveMaterial;
                collisions = Physics2D.OverlapBoxAll(new Vector2(transform.position.x, transform.position.y), new Vector2(transform.localScale.x, transform.localScale.y), 0);
                foreach (Collider2D col in collisions)
                {
                    if (col.gameObject.GetComponent <Player>())
                    {
                        col.gameObject.GetComponent <Player>().HP--;
                    }
                }
            }
            _activationTimer -= Time.deltaTime;
        }

        if (_active)
        {
            ActivateTrap(true);
            if (_holdTimer <= 0)
            {
                _active    = false;
                _holdTimer = HoldTime;
                ActivateTrap(false);
                GetComponent <Renderer>().material = SpikeTrapMaterial;
            }

            _holdTimer -= Time.deltaTime;
        }
    }
Beispiel #11
0
 public void Activate()
 {
     if (arm.localRotation.z == 180)
     {
         Physics2D.OverlapBoxAll(arm.position - Vector3.up, Vector2.one, 0f);
         foreach (Part cabledObject in cabledObjects)
         {
             cabledObject.gameObject.transform.position = Vector3.down * 5f;
         }
     }
     else if (arm.localRotation.z == 0)
     {
         Debug.Log("Activated");
         Physics2D.OverlapBoxAll(arm.position + Vector3.up, Vector2.one, 0f);
         foreach (Part cabledObject in cabledObjects)
         {
             cabledObject.gameObject.transform.position = Vector3.up * 5f;
         }
     }
     else if (arm.localRotation.z == 90)
     {
         Physics2D.OverlapBoxAll(arm.position + Vector3.right, Vector2.one, 0f);
         foreach (Part cabledObject in cabledObjects)
         {
             cabledObject.gameObject.transform.position = Vector3.right * 5f;
         }
     }
     else if (arm.localRotation.z == 270)
     {
         Physics2D.OverlapBoxAll(arm.position - Vector3.right, Vector2.one, 0f);
         foreach (Part cabledObject in cabledObjects)
         {
             cabledObject.gameObject.transform.position = Vector3.left * 5f;
         }
     }
     Debug.Log(arm.localRotation.z);
 }
Beispiel #12
0
        IEnumerator Attack()
        {
            enemyMovement.direction.x = 0;
            float lookAtPlayerRotationY;

            lookAtPlayerRotationY = GameManager.instance.playerPhysics.transform.position.x < enemyPhysics.position.x ? 180 : 0;
            enemyPhysics.rotation = Quaternion.Euler(0, lookAtPlayerRotationY, 0);
            animator.Play(attackAnimHash);
            float attackTime = animTimeDictionary[attackAnimHash];

            while (attackTime > 0)
            {
                if (canAttack)
                {
                    Collider2D[] colliders = Physics2D.OverlapBoxAll(attackBox.transform.position, attackBoxArea, 0);
                    foreach (Collider2D collider in colliders)
                    {
                        if (collider.tag == "Player")
                        {
                            collider.transform.GetChild(1).GetComponent <PlayerStatus>().
                            TakeDamage(attackDamage, DamageType.Melee, transform.rotation);
                        }
                        canAttack = false;
                    }
                }
                if (currentState != State.Attack)
                {
                    yield break;
                }
                attackTime -= coroutineCycle;
                yield return(waitTime);
            }
            if (currentState == State.Attack)
            {
                currentState = State.Chase;
            }
        }
    private void CollisionWithPlayer(Vector2 center, BoxCollider2D myCollider)
    {
        if (platform != null)         // do not need to check for collision when a passenger of a "platform"
        {
            return;
        }

        // need to sort the colliders
        Collider2D[] colliders = Physics2D.OverlapBoxAll(center, GetComponent <BoxCollider2D>().size, 0, 1 << LayerMask.NameToLayer("Cactus"));
        foreach (Collider2D collider in colliders)
        {
            if (collider.GetInstanceID() == myCollider.GetInstanceID())             // do not want to resolve collision with our own collider
            {
                continue;
            }

            CactusBehaviour cactusBehaviour   = collider.gameObject.GetComponent <CactusBehaviour>();
            Vector3         otherPrevPosition = cactusBehaviour.prevPosition;
            BoxCollider2D   otherCollider     = (BoxCollider2D)collider;
            float           colliderBottom    = myCollider.transform.position.y - myCollider.bounds.extents.y;
            float           otherColliderTop  = otherCollider.transform.position.y + otherCollider.bounds.extents.y;

            // when a collsion has occurred from the bottom
            if (prevPosition.y > otherPrevPosition.y)
            {
                // when this instance does not have a "parent" platform
                if (platform == null)
                {
                    platform   = otherCollider.gameObject;
                    platformId = cactusBehaviour.id;
                    transform.SetParent(otherCollider.gameObject.transform);
                }
                transform.Translate(0, otherColliderTop - colliderBottom, 0);                 // resolve the collision by moving away from the other collider
                vspeed = 0;
            }
        }
    }
    /**
     * <summary>
     * Watch for the item on top of the belt
     * Move the items to the origin point then move it downward
     * </summary>
     */
    protected override void WatchForItem()
    {
        Bounds  bounds = this.transform.GetComponent <Collider2D>().bounds;
        Vector2 size   = bounds.size;

        Collider2D[] colliders = Physics2D.OverlapBoxAll(this.transform.position, size, 0);
        foreach (Collider2D collider in colliders)
        {
            if (collider.tag == Tags.Item)
            {
                Transform item       = collider.GetComponent <Transform>();
                Bounds    itemBounds = item.GetComponent <Collider2D>().bounds;
                Vector2   itemPoint  = new Vector2(itemBounds.min.x, itemBounds.min.y);

                // Always move when the item is exactly or more on top of the collider
                if (!bounds.Contains(itemPoint))
                {
                    continue;
                }

                // Has the item reached the origin point?
                if (this.transform.position.y - item.position.y > 0)
                {
                    ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                    itemBehaviour.speed = 5f;
                    itemBehaviour.MoveUp();
                }
                // If the item has reached the origin point, move it to right
                else
                {
                    ItemBehaviour itemBehaviour = item.GetComponent <ItemBehaviour>();
                    itemBehaviour.speed = 5f;
                    itemBehaviour.MoveRight();
                }
            }
        }
    }
    public void Interact()
    {
        float directionX = playerInfo.facing == Direction.Left ? -1 : 1;
        float rayLength  = 2f;

        Collider2D[] hit = Physics2D.OverlapBoxAll(coll.bounds.center, coll.size * rayLength, 0, interactionMask);

        for (int i = 0; i < hit.Length; i++)
        {
            if (hit[i].tag == "InteractiveObject")
            {
                InteractiveObject interactiveObject = hit[i].GetComponent <InteractiveObject>();
                interactiveObject.Interact(this);
            }
        }

        /*int rayCount = 4;
         * float raySpacing = coll.bounds.size.y / (rayCount - 1);
         *
         * for (int i = 0; i < rayCount; i++)
         * {
         *  Vector2 rayOrigin = new Vector2(directionX == 1 ? coll.bounds.min.x : coll.bounds.max.x, coll.bounds.max.y);
         *  rayOrigin += Vector2.down * (raySpacing * i);
         *  RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, interactionMask);
         *
         *  Debug.DrawRay(rayOrigin, Vector2.right * directionX * rayLength, Color.red);
         *
         *  if (hit)
         *  {
         *      if (hit.collider.tag == "InteractiveObject")
         *      {
         *          InteractiveObject interactiveObject = hit.collider.GetComponent<InteractiveObject>();
         *          interactiveObject.Interact(this);
         *      }
         *  }
         * }*/
    }
Beispiel #16
0
    IEnumerator Attack()
    {
        yield return(new WaitForSeconds(55f / 60f));

        Collider2D[] colliders = Physics2D.OverlapBoxAll(attackOrigin.position, attackBoxScale, 0, 1 << LayerMask.NameToLayer("Player"));

        List <GameObject> received = new List <GameObject>();

        foreach (Collider2D collider in colliders)
        {
            if (received.Contains(collider.gameObject))
            {
                continue;
            }
            received.Add(collider.gameObject);
            if (collider.GetComponent <PlayerController>())
            {
                PlayerController.instance.TakeDamage();
            }
        }
        yield return(new WaitForSeconds((125f - 55f) / 60f));

        attacking = false;
    }
    public override void DefaultAttack()
    {
        if (!isChanneling)
        {
            float DefaultKnockBack = KnockBackPower * 0.1f;
            animator.SetTrigger("_DefaultAttack");
            MainCameraAnimator.SetTrigger("_Shake");
            Collider2D[] enemiesToDamage = Physics2D.OverlapBoxAll(DefaultAttackPosition.position,
                                                                   new Vector2(AttackRange, AttackRange + (AttackRange / 2)), 0, EnemyMask);


            foreach (var enemyCollider in enemiesToDamage)
            {
                foreach (var vulnerable in enemyCollider.GetComponents <UnitType.IVulnerable>())
                {
                    vulnerable.TakeDamage(Damage);
                }
                foreach (var knockbackable in enemyCollider.GetComponents <UnitType.IKnockBackAble>())
                {
                    knockbackable.KnockBack(DefaultKnockBack, transform.position);
                }
            }
        }
    }
Beispiel #18
0
 void CheckPushBlock()
 {
     Collider2D[] collider2Ds =
         Physics2D.OverlapBoxAll(transform.rotation.y == 0 ?
                                 boxCollider.bounds.center + Vector3.right * 0.25f + Vector3.up * 0.5f:
                                 boxCollider.bounds.center + Vector3.left * 0.25f + Vector3.up * 0.5f, checkPushBlockArea, 0);
     foreach (Collider2D collider in collider2Ds)
     {
         if (collider.gameObject.layer == LayerMask.NameToLayer("PushBlock"))
         {
             if (collider.GetComponent <PushBlockController>().velocity.y == 0)
             {
                 if ((transform.position.x < collider.transform.position.x && playerInput.directionalInput.x > 0) ||
                     (transform.position.x > collider.transform.position.x && playerInput.directionalInput.x < 0))
                 {
                     if (player.stateMachine.CurrentState != player.idle &&
                         player.stateMachine.CurrentState != player.run &&
                         player.stateMachine.CurrentState != player.pushBlock)
                     {
                         return;
                     }
                     player.stateMachine.SetState(player.pushBlock);
                     if (player.stateMachine.CurrentState != player.pushBlock)
                     {
                         return;
                     }
                     if (playerInput.directionalInput.x == 0)
                     {
                         return;
                     }
                     collider.GetComponent <PushBlockController>().direction.x = transform.rotation.y == 0 ? 1 : -1;
                 }
             }
         }
     }
 }
Beispiel #19
0
    void Attack2(float damageMultiplier, bool knockback = true) //knockback has short stun
    {
        Collider2D[] hitPlayer = Physics2D.OverlapBoxAll(enAttackPoint2.position, enAttackRange2, 180, playerLayer);

        foreach (Collider2D player in hitPlayer) //loop through enemies hit
        {
            if (player.GetComponent <PlayerCombat>() != null)
            {
                player.GetComponent <PlayerCombat>().TakeDamage(enAttackDamage * damageMultiplier); //attackDamage + additional damage from parameter
                float distToPlayer = transform.position.x - player.transform.position.x;            //getting player direction to enemy //if 0 will use last direction
                if (knockback)
                {
                    if (distToPlayer > 0)
                    {
                        player.GetComponent <PlayerCombat>().GetKnockback(false); //knockback to left
                    }
                    else
                    {
                        player.GetComponent <PlayerCombat>().GetKnockback(true); //knockback to right
                    }
                }
            }
        }
    }
Beispiel #20
0
        protected Vector2 CheckUpperGround()
        {
            var boxSize         = new Vector2(3f, 5f);
            var centerDownPoint = PlayerRightBottom + new Vector2(boxSize.x / 2, boxSize.y / 2 + GroundUnderPrecision);

            var overlaps = Physics2D.OverlapBoxAll(centerDownPoint, boxSize, 0);
            var filtered = overlaps.Where(c => c.CompareTag(TagNames.GROUND));

            Vector2 min = Vector2.positiveInfinity;

            foreach (var c in filtered)
            {
                var point = GetColliderLeftTop((BoxCollider2D)c);
                if (min.x.FloatGreater(point.x) &&
                    (centerDownPoint.y + boxSize.y / 2).FloatGreater(point.y) &&
                    point.x.FloatGreater(PlayerRightBottom.x))
                {
                    min = point;
                }
            }


            return(min);
        }
    /// <summary>
    /// Retorna todos os objetos encontrados nas layers desejadas
    /// </summary>
    /// <param name="pos"> Posição da tile</param>
    /// <param name="layers"> Nº das layers a serem vasculhadas </param>
    public List <GameObject> tileContent(Vector2 pos, params int[] layers)
    {
        Vector2           center   = centerPosition(pos); // Garante centralização
        List <GameObject> contents = new List <GameObject>();

        // LayerMask's BitMagic
        int layerMask = 0;

        foreach (int i in layers)
        {
            layerMask |= 1 << i;
        }

        Collider2D[] collidersInTile = Physics2D.OverlapBoxAll(center, new Vector2(0.9f, 0.9f), 0, layerMask);
        foreach (Collider2D collider in collidersInTile)
        {
            if (centerPosition(collider.gameObject.transform.position) == center || collider.gameObject.CompareTag("GridBlocks") ||
                collider.gameObject.CompareTag("Border"))
            {
                contents.Add(collider.gameObject);
            }
        }
        return(contents);
    }
Beispiel #22
0
    void Update()
    {
        Collider2D[] detectedObjects = Physics2D.OverlapBoxAll(gameObject.transform.position, gateSize, 0, layerMask);
        if (detectedObjects.Length > 0)
        {
            if (KeyCollectable.keysCollected == 3 && gateDoorPassed == false)
            {
                KeyCollectable.keysCollected = 0;
                foreach (GameObject key in KeyCollectable.storeForSpawn)
                {
                    Destroy(key);
                }
                KeyCollectable.storeForSpawn.Clear();

                gameObject.GetComponent <MeshRenderer>().enabled  = false;
                gameObject.GetComponent <BoxCollider2D>().enabled = false;

                gateDoorPassed = true;

                // Move player to teleport spot
                detectedObjects[0].transform.position = teleportSpot.transform.position;
            }
        }
    }
Beispiel #23
0
    private void Throw()
    {
        Collider2D[] colls = Physics2D.OverlapBoxAll(transform.position, areaDragSizeVec, 0, whatIsObstacle);

        // Check is there obstacle in the place of throwing the object
        // If there is no obstacles
        if (colls.Length == 0)
        {
            // Throw in front of player

            isDragging = false;

            Destroy(draggedObjFake);
            draggedObjFake = null;

            draggedObj.SetActive(true);
            draggedObj.transform.position = gameObject.transform.position;
            draggedObj.GetComponent <Rigidbody2D>().AddForce((PlayerStats.instance.lookDirection + Vector2.up) * ThrowForce,
                                                             ForceMode2D.Impulse);
            draggedObj = null;
        }

        /*  else // If there is some obstacle
         * {
         *
         *    // Put object behind player
         *    isDragging = false;
         *
         *    Destroy(draggedObjFake);
         *    draggedObjFake = null;
         *
         *    draggedObj.SetActive(true);
         *    draggedObj.transform.position = putBackArea.position;
         *    draggedObj = null;
         * }*/
    }
Beispiel #24
0
    // Primary Attack for melee weapons
    override public void FirstAttack(bool isAttacking)
    {
        // Add the time since Update was last called to the timer.
        timer += Time.deltaTime;

        // If player is attacking
        if (isAttacking && timer >= timeBetweenAttacks && !block)
        {
            anim.SetTrigger("Melee");
            audioManager.Play(swishSound);
            // Reset the timer.
            timer = 0f;
            Collider2D[] cols = Physics2D.OverlapBoxAll(attackCollider.bounds.center, attackCollider.bounds.extents, 0.0f, LayerMask.GetMask("Hitbox"));
            foreach (Collider2D c in cols)
            {
                if (c.transform.root == transform)
                {
                    continue;
                }
                c.SendMessageUpwards("ApplyDamage", damageFirst, SendMessageOptions.DontRequireReceiver);
                audioManager.Play(hitSound);
            }
        }
    }
Beispiel #25
0
        /// <summary>
        /// Checks for interatable objects in a local radius, then activates them.
        /// </summary>
        public void OnAcceptKey()
        {
            // Setup the collision area
            collisions = Physics2D.OverlapBoxAll(_transform.position, interactionAreaSize,
                                                 _transform.rotation.z);

            // Go through every item collided with
            foreach (var collider in collisions)
            {
                if (collider.gameObject == gameObject)
                {
                    continue;
                }

                // Check for the interactable interface
                var interactable = collider.GetComponent <IInteractable>();

                // If that interface exists, send an interacted event.
                if (interactable != null)
                {
                    interactable.OnInteracted();
                }
            }
        }
Beispiel #26
0
    private IEnumerator AttackDelay()
    {
        yield return(new WaitForSeconds(attackDelay));

        Collider2D[] enemiesToDamage = Physics2D.OverlapBoxAll(attackPos.position, new Vector2(attackRangeX, attackRangeY), 0, whatIsEnemies);

        CameraMove.Shake((transform.position - mousePos).normalized, 5f, 0.1f);

        for (int i = 0; i < enemiesToDamage.Length; i++)
        {
            //knockback
            Rigidbody2D enemy = enemiesToDamage[i].GetComponent <Rigidbody2D>();
            enemiesToDamage[i].GetComponent <Enemy>().TakeDemage(damage);

            if (enemy != null)
            {
                enemy.isKinematic = false;
                Vector2 difference = enemy.transform.position - transform.position;
                difference = difference.normalized * thrust;
                enemy.AddForce(difference, ForceMode2D.Impulse);
                StartCoroutine(KnockCo(enemy));
            }
        }
    }
Beispiel #27
0
    private void killEnemiesAndHurtBuildings(Team senderTeam, Vector3 Pos)
    {
        Collider2D[] colliders;

        //GetComponent<BoxCollider2D>().OverlapCollider((new ContactFilter2D().NoFilter()), colliders);

        colliders = Physics2D.OverlapBoxAll(Pos, new Vector2(bombRange, bombRange), 90);
        foreach (Collider2D c in colliders)
        {
            Debug.Log(c.name);
            if (c != null)
            {
                if (c.tag == "BasicUnit")
                {
                    c.gameObject.SetActive(false);
                }
                else if (c.tag == "Base")
                {
                    c.gameObject.GetComponent <Base>().affectPopulation(new popOp(15, senderTeam, popOpType.BombstrikeOnBase));
                    c.gameObject.GetComponent <Base>().bounce();
                }
            }
        }
    }
    Food SomethingToCollect()
    {
        // Enemies can't pickup food (for now...)
        if (character.GetType() != typeof(Player))
        {
            return(null);
        }

        Collider2D[] colliders = Physics2D.OverlapBoxAll(
            groundCheck.bounds.center,
            groundCheck.bounds.size,
            0f,
            foodMask);

        if (colliders.Length > 0)
        {
            Food f = colliders[0].GetComponent <Food>();
            if (f.readyToPickUp)
            {
                return(f);
            }
        }
        return(null);
    }
Beispiel #29
0
    private void GetAreaEntities()
    {
        var           cols = GetComponents <BoxCollider2D>();
        BoxCollider2D col  = null;

        foreach (var c in cols)
        {
            if (c.isTrigger)
            {
                continue;
            }
            col = c;
        }
        if (col == null)
        {
            throw new Exception("Colliders improperly setup on CheckPoint. Area collider should not be a trigger, second collider for interact approach SHOULD be a trigger.");
        }
        var hits = Physics2D.OverlapBoxAll(col.transform.position + new Vector3(col.offset.x, col.offset.y), col.size, 0);

        foreach (var hit in hits)
        {
            Unit u = hit.GetComponent <Unit>();
            if (u != null)
            {
                units.Add(u);
            }
        }

        foreach (var u in units)
        {
            Debug.Log($"[{this.name}] - parenting {u.name}");
        }

        col.enabled = false;
        Destroy(col);
    }
Beispiel #30
0
    // Update is called once per frame
    void Update()
    {
        if (isActive)
        {
            Collider2D[] d = Physics2D.OverlapBoxAll(transform.position, boxSize, Vector2.Angle(Vector2.up, transform.up), target);
            //Debug.Log(transform.eulerAngles.z);
            //Debug.Log(d.Length);

            foreach (Collider2D o in d)
            {
                Debug.Log(o.name);
                if (o.gameObject != owner)
                {
                    if (o.tag != "Rock")
                    {
                        Damageable.CollisionInfo i = new Damageable.CollisionInfo();
                        i.position = transform.position;
                        i.totalDmg = 1;
                        o.GetComponent <Damageable>().DealDamage(i);
                        //hitFX.transform.position = o.transform.position;
                        //hitFX.Emit(20);
                    }

                    if (o.gameObject.layer == LayerMask.NameToLayer("Enemy"))
                    {
                        hitFX.transform.position = o.transform.position;
                        hitFX.Emit(20);
                    }
                    //o.GetComponent<Damageable>().DealDamage(1);
                }
            }
        }
        else
        {
        }
    }